codice:
Option Explicit
Private Declare Function ExtFloodFill Lib "Gdi32" (ByVal hdc As Long, ByVal _
X As Long, ByVal Y As Long, ByVal crColor As Long, ByVal wFillType As Long) As _
Long
Dim X1, Y1 As Single
Dim Disegna As Boolean
Private Sub Form_Load()
Picture1.DrawWidth = 3
Picture1.FillStyle = vbSolid
Picture1.ScaleMode = 3
Picture1.FillColor = vbBlack
End Sub
Private Sub Form_Resize()
Picture1.Width = Me.Width
Picture1.Height = Me.Height
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X _
As Single, Y As Single)
Disegna = 1
If Button = vbLeftButton Then
X1 = X
Y1 = Y
End If
If Button = vbRightButton Then
Picture1.FillColor = RGB(Int(Rnd * 255), Int(Rnd * 255), Int(Rnd * 255))
ExtFloodFill Picture1.hdc, X, Y, RGB(0, 0, 0), 1 'FLOODFILLBORDER
End If
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X _
As Single, Y As Single)
Label1.Caption = X
Label2.Caption = Y
If Button = vbLeftButton Then
'If Disegna = True Then
'Picture1.Line (X1, Y1)-(X, Y)
'X1 = X
'Y1 = Y
'End If
End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X _
As Single, Y As Single)
If Disegna = True Then
Picture1.Line (X1, Y1)-(X, Y)
X1 = X
Y1 = Y
End If
Disegna = False
End Sub
in poche parole non devi + disegnare quando muovi il mouse, ma quando lasci il tasto. Devi solo spostare il codice ...
codice:
If Disegna = True Then
Picture1.Line (X1, Y1)-(X, Y)
X1 = X
Y1 = Y
End If
... in MouseUp