لكني لم اقصد هذا بل قصدت عند الضغط على نفس الاداة وتحريكها فوق اداة اخرى
وضعت مثال لذلك
لكن المثال عملته بطريقة اخرى لعدم تمكني من عمل ما اريد
اريد عند تحريك اداة Button فوق اداة TextBox بمجرد دخول اداة Button فوق اداة Textbox يتم وضع
اداة الـ Button فوق اداة Textbox حسب الـ Location لاداة TextBox
شاهد المثال وستعرف قصدي
المثال اضغط على اداة الـ Button سيتغير لونه ثم اضغط على احد مربعات النصوص وشاهد سينتقل الـ Button فوقه مباشرة
لكني اريده بالضغط والافلات فوق التكست بوكس
السلام عليكم،
تم التعديل على الكود ليعمل كما تريد
الكود بعد التعديل:
كود :
Public Class Form1
Public Const WM_NCLBUTTONDOWN = &HA1
Public Const HTCAPTION = 2
Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
Button1.Capture = False
Dim msg As Message = _
Message.Create(Button1.Handle, WM_NCLBUTTONDOWN, _
New IntPtr(HTCAPTION), IntPtr.Zero)
Me.DefWndProc(msg)
End If
Me.Button1.BackColor = Color.Violet
End Sub
Private Sub Button2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
Button2.Capture = False
Dim msg As Message = _
Message.Create(Button2.Handle, WM_NCLBUTTONDOWN, _
New IntPtr(HTCAPTION), IntPtr.Zero)
Me.DefWndProc(msg)
End If
Me.Button2.BackColor = Color.Violet
End Sub
Private Sub Button3_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button3.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
Button3.Capture = False
Dim msg As Message = _
Message.Create(Button3.Handle, WM_NCLBUTTONDOWN, _
New IntPtr(HTCAPTION), IntPtr.Zero)
Me.DefWndProc(msg)
End If
Me.Button3.BackColor = Color.Violet
End Sub
Private Sub Button4_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button4.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
Button4.Capture = False
Dim msg As Message = _
Message.Create(Button4.Handle, WM_NCLBUTTONDOWN, _
New IntPtr(HTCAPTION), IntPtr.Zero)
Me.DefWndProc(msg)
End If
Me.Button4.BackColor = Color.Violet
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Me.Button1.Location = New System.Drawing.Point(149, 66)
Me.Button2.Location = New System.Drawing.Point(12, 66)
Me.Button3.Location = New System.Drawing.Point(12, 24)
Me.Button4.Location = New System.Drawing.Point(149, 24)
Private Sub TextBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox2.MouseDown
If Me.Button1.BackColor = Color.Violet Then
Me.Button1.Location = New System.Drawing.Point(12, 132)
If Me.Button1.Location = New System.Drawing.Point(12, 132) Then
Me.Button1.BackColor = Color.Empty
MsgBox("صح")
TextBox2.Location = New Point(Button1.Left, Button1.Top - Button1.Height)
End If
End If
If Me.Button2.BackColor = Color.Violet Then
Me.Button2.Location = New System.Drawing.Point(12, 132)
If Me.Button2.Location = New System.Drawing.Point(12, 132) Then
Me.Button2.BackColor = Color.Empty
MsgBox("خطأ")
TextBox2.Location = New Point(Button2.Left, Button2.Top - Button2.Height)
End If
End If
If Me.Button3.BackColor = Color.Violet Then
Me.Button3.Location = New System.Drawing.Point(12, 132)
If Me.Button3.Location = New System.Drawing.Point(12, 132) Then
Me.Button3.BackColor = Color.Empty
MsgBox("خطأ")
TextBox2.Location = New Point(Button3.Left, Button3.Top - Button3.Height)
End If
End If
If Me.Button4.BackColor = Color.Violet Then
Me.Button4.Location = New System.Drawing.Point(12, 132)
If Me.Button4.Location = New System.Drawing.Point(12, 132) Then
Me.Button4.BackColor = Color.Empty
MsgBox("خطأ")
TextBox2.Location = New Point(Button4.Left, Button4.Top - Button4.Height)
End If
End If
End Sub
Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
If Me.Button1.BackColor = Color.Violet Then
Me.Button1.Location = New System.Drawing.Point(149, 132)
If Me.Button1.Location = New System.Drawing.Point(149, 132) Then
Me.Button1.BackColor = Color.Empty
MsgBox("خطأ")
TextBox1.Location = New Point(Button1.Left, Button1.Top - Button1.Height)
End If
End If
If Me.Button2.BackColor = Color.Violet Then
Me.Button2.Location = New System.Drawing.Point(149, 132)
If Me.Button2.Location = New System.Drawing.Point(149, 132) Then
Me.Button2.BackColor = Color.Empty
MsgBox("صح")
TextBox1.Location = New Point(Button2.Left, Button2.Top - Button2.Height)
End If
End If
If Me.Button3.BackColor = Color.Violet Then
Me.Button3.Location = New System.Drawing.Point(149, 132)
If Me.Button3.Location = New System.Drawing.Point(149, 132) Then
Me.Button3.BackColor = Color.Empty
MsgBox("خطأ")
TextBox1.Location = New Point(Button3.Left, Button3.Top - Button3.Height)
End If
End If
If Me.Button4.BackColor = Color.Violet Then
Me.Button4.Location = New System.Drawing.Point(149, 132)
If Me.Button4.Location = New System.Drawing.Point(149, 132) Then
Me.Button4.BackColor = Color.Empty
MsgBox("خطأ")
TextBox1.Location = New Point(Button4.Left, Button4.Top - Button4.Height)
End If
End If
End Sub
End Class
لكن ليس هذا ما قصدت تحريك الاداه هذا جميل جداً لكن اريد بعد تحريك الاداة من خلال
السحب ومرورها فوق التكست بمجرد دخولها فوق التكست والافلات يتم لصق الاداة فوق التكست
في مشروع الأخ DreamsDotNet إستبدل الأمر الموجود في Button1_MouseUp بالأمر التالي :
كود :
Private Sub Button1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
Button1.Cursor = Cursors.Default
Dim P As Point = (Button1.Location + e.Location)
If P.X >= TextBox1.Left AndAlso P.X <= TextBox1.Left + TextBox1.Width Then
If P.Y >= TextBox1.Top AndAlso P.Y <= TextBox1.Top + TextBox1.Height Then
TextBox1.Controls.Add(Button1)
Button1.Dock = DockStyle.Fill
End If
End If
End Sub