robotic1981
پنج شنبه 05 شهریور 1388, 12:07 عصر
سلام
من میخوام picturebox2 را روی picturebox1 جابجا کنم،من کد زیر را نوشته ام اما این کد picturebox2 را روی کل فرم جابجا میکند،لطفا راهنماییم کنین.
Public Class Form1
Private oControlOffsetPoint As Point
Private Sub PictureBox2_MouseMove_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseMove
Dim sX As Integer = RectangleToClient(New Rectangle(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y, 1, 1)).Left - oControlOffsetPoint.X
Dim sY As Integer = RectangleToClient(New Rectangle(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y, 1, 1)).Top - oControlOffsetPoint.Y
If e.Button = Windows.Forms.MouseButtons.Left Then
sender.Location = New Point(sX, sY)
PictureBox2.Left = sX
PictureBox2.Top = sY
End If
PictureBox2.BringToFront()
End Sub
End Class
من میخوام picturebox2 را روی picturebox1 جابجا کنم،من کد زیر را نوشته ام اما این کد picturebox2 را روی کل فرم جابجا میکند،لطفا راهنماییم کنین.
Public Class Form1
Private oControlOffsetPoint As Point
Private Sub PictureBox2_MouseMove_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseMove
Dim sX As Integer = RectangleToClient(New Rectangle(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y, 1, 1)).Left - oControlOffsetPoint.X
Dim sY As Integer = RectangleToClient(New Rectangle(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y, 1, 1)).Top - oControlOffsetPoint.Y
If e.Button = Windows.Forms.MouseButtons.Left Then
sender.Location = New Point(sX, sY)
PictureBox2.Left = sX
PictureBox2.Top = sY
End If
PictureBox2.BringToFront()
End Sub
End Class