Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
On my form i move objects around by selecting it then using Up, Down, Left, Right buttons to move it.

Instead of doing one move per click i would like to have the option to hold the button down and it keeps moving the object until the button is not pressed down anymore.

I thought this would be simple, I don't really want to use Timers on the Mouse Down and Mouse Up Events (Unless that simply is the only way this can be done)

Looking for Alternative ideas.

What I have tried:

Tried using a Timer and Mouse Down, Mouse Up events on the button. Wasn't ideal but i could spend a while tweaking it until it's right, just wanted any other suggestions before i do that.
Posted
Updated 16-Aug-17 4:30am
Comments
Richard Deeming 17-Aug-17 10:38am    
Maybe something like this?
Auto-repeat button in 10 minutes[^]
BeginnerCoderPete 17-Aug-17 10:43am    
Thank you, I was thinking today i kind of got off track from my original question and would still like an answer to it, so thank you for that!!

1 solution

The MouseDown and MouseMove events of a control. Here is an example (in C#) that is easy to understand and demonstrates a method: location - Moving a control by dragging it with the mouse in C# - Stack Overflow[^] which translates to:
VB
Private MouseDownLocation As Point

Private Sub pictureBox1_MouseDown(sender As Object, e As MouseEventArgs)
	If e.Button = System.Windows.Forms.MouseButtons.Left Then
		MouseDownLocation = e.Location
	End If
End Sub

Private Sub pictureBox1_MouseMove(sender As Object, e As MouseEventArgs)
	If e.Button = System.Windows.Forms.MouseButtons.Left Then
		pictureBox1.Left = e.X + pictureBox1.Left - MouseDownLocation.X
		pictureBox1.Top = e.Y + pictureBox1.Top - MouseDownLocation.Y
	End If
End Sub
 
Share this answer
 
v2
Comments
BeginnerCoderPete 16-Aug-17 10:00am    
Unfortunately the Objects i am moving are on a control that has no click event or Mouse Events at all actually other than 'MouseCaptureChanged' which doesn't actually work on the part of the control i need. If it helps it is a Synrad WinMark Pro ActiveX control.

I am able to select objects and move them through code, so this is why i am having to use buttons to move them about the page.
Graeme_Grant 16-Aug-17 10:03am    
The above solution should be supported. You need to contact the author of the "Synrad WinMark Pro ActiveX control" and ask them how to do it.
BeginnerCoderPete 16-Aug-17 10:08am    
I have been in contact with Synrad and the representative i was speaking to is aware there is no click events or mouse events for the control, his explanation was that it's only really used for previewing the image to be etched. Although all the methods are there to select and move individual objects.

If i just had some way to detect a click on the control i could go from there but unfortunately there is no way, or so i am told.

So my alternative was to use buttons, i just wanted better than 1 move per click. I have an option to increase the distance the object moves per click but i would still prefer to just be able to hold the button down if i wanted to move an object far.
Graeme_Grant 16-Aug-17 10:12am    
Why not have an "edit mode"? Then when "edit mode" is active, have controls that "adorn" the Synad control to allow adjustments, a bit like Microsoft's Panel control - it has a drag adorner on the top left in the form designer window.
BeginnerCoderPete 16-Aug-17 10:32am    
Right OK, i will have a look at 'adorning' it is a term i haven't come across yet so not exactly sure but i have a rough idea and i think i have had the idea but then no idea how to go about it. I will look it up, Thank you for the advice.

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