Click here to Skip to main content
15,889,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I made a user control.
same user control drag 3 time in picture box and now i want to move multiple user control in picture box at runtime

What I have tried:

I have tried this code but its working on button control..


Public Class test
Dim a As Boolean = False

Private Sub Button1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
a = False
End Sub

Private Sub Button1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
a = True
End Sub

Private Sub Button1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove

If a = True Then

Button1.Left = Control.MousePosition.X - Me.Left - 10
Button1.Top = Control.MousePosition.Y - Me.Top - 40

End If

End Sub

End Class
Posted
Updated 9-Jul-16 1:07am
Comments
BillWoodruff 9-Jul-16 13:24pm    
Please clarify: are you wanting to move PictureBoxes inside a UserControl ?

Also, please update your code to show your use of PictureBox elements and UserControl.

1 solution

Firstly, that's VB, not C# - it's important to tag your question correctly!
Second, if it works for a Button then it should work for a UserControl.
The best way to do it is to replace the fixed dependency on Button1 with a generic Control, and use the sender parameter to identify the control that is involved:
VB.NET
Private Sub Control_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs)
	Dim c As Control = TryCast(sender, Control)
	If a = True Then
		c.Left = Control.MousePosition.X - Me.Left - 10
		c.Top = Control.MousePosition.Y - Me.Top - 40
	End If
End Sub
And use that to handle your events.
 
Share this answer
 
Comments
BillWoodruff 9-Jul-16 13:25pm    
I fear the poster may literally mean what they say in their title, and have placed a UserControl(s) inside a PictureBox; I've asked them a question about that in a comment :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900