27-10-19, 11:03 PM
كود :
Const HW As Integer = 40
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
If b Then
For i As Integer = 0 To Me.Height Step HW
e.Graphics.DrawLine(Pens.Black, 0, i, Me.Width, i)
Next
For j As Integer = 0 To Me.Width Step HW
e.Graphics.DrawLine(Pens.Black, j, 0, j, Me.Height)
Next
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Size = New Size(80, 80)
Button1.Location = New Point(80, 80)
Button1.FlatStyle = FlatStyle.Flat
End Sub
Dim b As Boolean = False
Dim x, y As Integer
Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
b = True
x = e.X : y = e.Y
Invalidate()
End Sub
Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove
If b Then
Button1.Location = New Point(Button1.Location.X + e.X - x, Button1.Location.Y + e.Y - y)
End If
End Sub
Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
b = False
Dim x1 As Integer = Button1.Location.X / 40
Dim y1 As Integer = Button1.Location.Y / 40
Button1.Location = New Point(x1 * 40, y1 * 40)
Invalidate()
End Sub
