Differenze tra le versioni di "Spostare con il mouse un cerchio in una DrawingArea"
Da Gambas-it.org - Wikipedia.
Riga 7: | Riga 7: | ||
Private dify As Short | Private dify As Short | ||
− | + | Public Sub _new() | |
With Me | With Me | ||
Riga 18: | Riga 18: | ||
End With | End With | ||
− | + | End | |
− | + | ||
+ | Public Sub Form_Arrange() | ||
x = (DrawingArea1.W / 2) - (RAGGIO / 2) | x = (DrawingArea1.W / 2) - (RAGGIO / 2) | ||
y = (DrawingArea1.H / 2) - (RAGGIO / 2) | y = (DrawingArea1.H / 2) - (RAGGIO / 2) | ||
− | + | End | |
− | + | ||
+ | Public Sub DrawingArea1_MouseDown() | ||
<FONT Color=gray>' ''Verifica se il punto ove si è cliccato con il mouse non è esterno alla circonferenza:''</font> | <FONT Color=gray>' ''Verifica se il punto ove si è cliccato con il mouse non è esterno alla circonferenza:''</font> | ||
Riga 35: | Riga 37: | ||
dify = y - Mouse.Y | dify = y - Mouse.Y | ||
− | + | End | |
− | + | ||
+ | Public Sub DrawingArea1_MouseMove() | ||
<FONT Color=gray>' ''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()":''</font> | <FONT Color=gray>' ''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()":''</font> | ||
Riga 49: | Riga 52: | ||
End With | End With | ||
− | + | End | |
− | + | ||
+ | Public Sub DrawingArea1_MouseUp() | ||
difx = -1 | difx = -1 | ||
DrawingArea1.Mouse = Mouse.Default | DrawingArea1.Mouse = Mouse.Default | ||
− | + | End | |
+ | |||
− | + | Public Sub DrawingArea1_Draw() | |
With Paint | With Paint | ||
Riga 66: | Riga 71: | ||
End With | End With | ||
− | + | End | |
Riga 72: | Riga 77: | ||
=Note= | =Note= | ||
[1] Vedere anche: | [1] Vedere anche: | ||
− | <BR> - [[ | + | <BR> - [[Spostare con il mouse un rettangolo in una DrawingArea]] |
− | <BR> - [[ | + | <BR> - [[Spostare con il mouse un'ellisse in una DrawingArea]] |
Versione attuale delle 14:51, 27 giu 2024
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