Differenze tra le versioni di "Disegnare in una DrawingArea sulla base dei punti cliccati un parallelogramma con angoli retti"
Da Gambas-it.org - Wikipedia.
(Creata pagina con "Cliccando <U>almeno due volte</u> all'interno di una ''DrawingArea'', si disegnerà un rettangolo o un quadrato ( a seconda dei casi), che sarà definito nella sua posizione i...") |
|||
Riga 2: | Riga 2: | ||
Mostriamo un possibile codice: | Mostriamo un possibile codice: | ||
+ | Private DrawingArea1 As DrawingArea | ||
+ | Private Button1 As Button | ||
+ | Private xx As New Short[] | ||
+ | Private yy As New Short[] | ||
+ | Private bo As Boolean | ||
− | + | ||
+ | Public Sub Form_Open() | ||
+ | |||
+ | With Me | ||
+ | .W = Screen.AvailableWidth * 0.5 | ||
+ | .H = Screen.AvailableHeight * 0.5 | ||
+ | End With | ||
+ | With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1" | ||
+ | .X = 0 | ||
+ | .Y = 0 | ||
+ | .W = Me.W | ||
+ | .H = Me.H * 0.8 | ||
+ | .Background = Color.SoftYellow | ||
+ | End With | ||
+ | With Button1 = New Button(Me) As "Button1" | ||
+ | .W = Me.W * 0.15 | ||
+ | .H = Me.H * 0.15 | ||
+ | .X = (Me.W / 2) - (.W / 2) | ||
+ | .Y = Me.H - .H | ||
+ | End With | ||
+ | |||
+ | End | ||
+ | |||
+ | |||
+ | Public Sub DrawingArea1_MouseUp() | ||
+ | |||
+ | xx.Push(Mouse.X) | ||
+ | yy.Push(Mouse.Y) | ||
+ | |||
+ | End | ||
+ | |||
+ | |||
+ | Public Sub Button1_Click() | ||
+ | |||
+ | bo = True | ||
+ | DrawingArea1.Refresh | ||
+ | |||
+ | End | ||
+ | |||
+ | |||
+ | Public Sub DrawingArea1_Draw() | ||
+ | |||
+ | If Not bo Then Return | ||
+ | |||
+ | Dim a, b, c As Short | ||
+ | |||
+ | With Paint | ||
+ | For c = 0 To xx.Max | ||
+ | .Arc(xx[c], yy[c], 2, Rad(0), Rad(360), False) | ||
+ | .Fill | ||
+ | Next | ||
+ | a = xx.Sort(gb.Ascent)[0] | ||
+ | b = yy.Sort(gb.Ascent)[0] | ||
+ | .DrawRect(xx.Sort(gb.Ascent)[0], yy.Sort(gb.Ascent)[0], xx.Sort(gb.Descent)[0] - a, yy.Sort(gb.Descent)[0] - b, Color.Red) | ||
+ | .Stroke | ||
+ | .End | ||
+ | End With | ||
+ | |||
+ | xx.Clear | ||
+ | yy.Clear | ||
+ | |||
+ | End |
Versione attuale delle 08:45, 16 gen 2024
Cliccando almeno due volte all'interno di una DrawingArea, si disegnerà un rettangolo o un quadrato ( a seconda dei casi), che sarà definito nella sua posizione in base al punto con i valori X e Y inferiori, e nella sua dimensioni con i predetti valori, ma superiori.
Mostriamo un possibile codice:
Private DrawingArea1 As DrawingArea Private Button1 As Button Private xx As New Short[] Private yy As New Short[] Private bo As Boolean Public Sub Form_Open() With Me .W = Screen.AvailableWidth * 0.5 .H = Screen.AvailableHeight * 0.5 End With With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1" .X = 0 .Y = 0 .W = Me.W .H = Me.H * 0.8 .Background = Color.SoftYellow End With With Button1 = New Button(Me) As "Button1" .W = Me.W * 0.15 .H = Me.H * 0.15 .X = (Me.W / 2) - (.W / 2) .Y = Me.H - .H End With End Public Sub DrawingArea1_MouseUp() xx.Push(Mouse.X) yy.Push(Mouse.Y) End Public Sub Button1_Click() bo = True DrawingArea1.Refresh End Public Sub DrawingArea1_Draw() If Not bo Then Return Dim a, b, c As Short With Paint For c = 0 To xx.Max .Arc(xx[c], yy[c], 2, Rad(0), Rad(360), False) .Fill Next a = xx.Sort(gb.Ascent)[0] b = yy.Sort(gb.Ascent)[0] .DrawRect(xx.Sort(gb.Ascent)[0], yy.Sort(gb.Ascent)[0], xx.Sort(gb.Descent)[0] - a, yy.Sort(gb.Descent)[0] - b, Color.Red) .Stroke .End End With xx.Clear yy.Clear End