con questo listato riesco a disegnare a mano libera, ma se invece volessi tracciare delle linee rette di cosa devo tenere conto?
codice:
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), 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)
Disegna = False
End Sub