Differenze tra le versioni di "Spostare con il mouse un cerchio in una DrawingArea"
Da Gambas-it.org - Wikipedia.
(3 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 1: | Riga 1: | ||
Nel seguente esempio si potrà spostare con il mouse sulla superficie di una ''DrawingArea'' un cerchio precedentemente disegnato. <SUP>[[[#Note|Nota 1]]]</sup> | Nel seguente esempio si potrà spostare con il mouse sulla superficie di una ''DrawingArea'' un cerchio precedentemente disegnato. <SUP>[[[#Note|Nota 1]]]</sup> | ||
+ | Private DrawingArea1 As DrawingArea | ||
Private Const RAGGIO As Float = 50.0 | Private Const RAGGIO As Float = 50.0 | ||
− | Private x As Short | + | Private x As Short |
− | Private y As Short | + | Private y As Short |
Private difx As Short = -1 | Private difx As Short = -1 | ||
Private dify As Short | Private dify As Short | ||
+ | '''Public''' Sub _new() | ||
+ | |||
+ | With Me | ||
+ | .W = Screen.AvailableWidth | ||
+ | .H = Screen.AvailableHeight | ||
+ | .Arrangement = Arrange.Fill | ||
+ | End With | ||
+ | With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1" | ||
+ | .Background = Color.White | ||
+ | End With | ||
+ | |||
+ | '''End''' | ||
+ | |||
+ | '''Public''' Sub Form_Arrange() | ||
+ | |||
+ | x = (DrawingArea1.W / 2) - (RAGGIO / 2) | ||
+ | y = (DrawingArea1.H / 2) - (RAGGIO / 2) | ||
+ | |||
+ | '''End''' | ||
'''Public''' Sub DrawingArea1_MouseDown() | '''Public''' Sub DrawingArea1_MouseDown() | ||
Riga 42: | Riga 62: | ||
With Paint | With Paint | ||
.Arc(x, y, RAGGIO, Rad(0), Rad(360), False) | .Arc(x, y, RAGGIO, Rad(0), Rad(360), False) | ||
− | . | + | .Stroke |
− | . | + | .End |
End With | End With | ||
Riga 53: | Riga 73: | ||
[1] Vedere anche: | [1] Vedere anche: | ||
<BR> - [[Spostare_con_il_mouse_un_rettangolo_in_una_DrawingArea|Spostare con il mouse un rettangolo in una DrawingArea]] | <BR> - [[Spostare_con_il_mouse_un_rettangolo_in_una_DrawingArea|Spostare con il mouse un rettangolo in una DrawingArea]] | ||
− | <BR> - [[Spostare_con_il_mouse_un' | + | <BR> - [[Spostare_con_il_mouse_un'ellisse_in_una_DrawingArea|Spostare con il mouse un'ellisse in una DrawingArea]] |
Versione attuale delle 22:27, 3 gen 2022
Nel seguente esempio si potrà spostare con il mouse sulla superficie di una DrawingArea un cerchio precedentemente disegnato. [Nota 1]
Private DrawingArea1 As DrawingArea Private Const RAGGIO As Float = 50.0 Private x As Short Private y As Short Private difx As Short = -1 Private dify As Short Public Sub _new() With Me .W = Screen.AvailableWidth .H = Screen.AvailableHeight .Arrangement = Arrange.Fill End With With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1" .Background = Color.White End With End Public Sub Form_Arrange() x = (DrawingArea1.W / 2) - (RAGGIO / 2) y = (DrawingArea1.H / 2) - (RAGGIO / 2) End Public Sub DrawingArea1_MouseDown() ' Verifica se il punto ove si è cliccato con il mouse non è esterno alla circonferenza: If Sqr(((Mouse.X - x) ^ 2) + ((Mouse.Y - y) ^ 2)) > RAGGIO Then Return difx = x - Mouse.X dify = y - Mouse.Y End Public Sub DrawingArea1_MouseMove() ' Se il punto, ove si è cliccato con il mouse è esterno alla circonferenza, allora la variabile "difx" non ha cambiato il valore assegnatogli dall'ultimo Evento "_MouseUp()": If difx == -1 Then Return x = Mouse.X + difx y = Mouse.Y + dify With DrawingArea1 .Mouse = 18 .Refresh End With End Public Sub DrawingArea1_MouseUp() difx = -1 DrawingArea1.Mouse = Mouse.Default End Public Sub DrawingArea1_Draw() With Paint .Arc(x, y, RAGGIO, Rad(0), Rad(360), False) .Stroke .End End With End
Note
[1] Vedere anche:
- Spostare con il mouse un rettangolo in una DrawingArea
- Spostare con il mouse un'ellisse in una DrawingArea