27-10-19, 10:20 PM (آخر تعديل لهذه المشاركة : 27-10-19, 10:24 PM {2} بواسطة 3booody.)
هل تقصد مربعات بهذا الشكل؟
كود :
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
27-10-19, 10:54 PM (آخر تعديل لهذه المشاركة : 27-10-19, 10:57 PM {2} بواسطة 3booody.)
تفضل اخي
فقط ضع زر بوتون في الفورم وجرب هذا الكود وان شاء الله يكون هو طلبك
كود :
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
28-10-19, 12:33 AM (آخر تعديل لهذه المشاركة : 28-10-19, 12:42 AM {2} بواسطة 3booody.)
تفضل اخي
لا اخي ماكو أي تعب تدلل
كود :
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