27-10-19, 10:05 PM
السلام عليكم
كيف ممكن اني اعمل شبكة على الفورم (مربعات صغيرة)
ووضع بوتن او بيكتشر وليكن اخذت 16 مربع
اريد كود تحريكها بحيث تثبت على 16 مربع من مربعات الشبكة
غير 16 مربع اللي كانت عليهن
Const HW As Integer = 40
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
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 Sub
Const HW As Integer = 40
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
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 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
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)
End Sub
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
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
If x1 * 40 > Me.Width - Button1.Width Then
x1 = (Me.Width - Button1.Width) / 40
End If
If x1 < 0 Then
x1 = 0
End If
If y1 * 40 > Me.Height - Button1.Height Then
y1 = (Me.Height - Button1.Height) / 40
End If
If y1 < 0 Then
y1 = 0
End If
Button1.Location = New Point(x1 * 40, y1 * 40)
Invalidate()
End Sub