Move Controls at Runtime with the Mouse in C# – Programming, Pseudocode Example, C# Programming Example
C# Windows Form

Move Controls at Runtime with the Mouse in C#

In this tutorial, I will show you How to Move Controls With The Mouse On A Form At Runtime.

Giving the user the ability to ‘design’ their application is not difficult. All we have to do is make the respective controls movable.
For this we create a global list in which we cache the controls that we want to make movable.

Form_Load Event:

Here we initialize the list of elements that can be moved and add the elements to this list using Add. Then we iterate over that list and subscribe to the MouseMove event for each element.

Here we only check whether the left mouse button was pressed and cast the event sender to a control. So that the control does not ‘disappear’ behind all the other controls, we still call .BringToFront () of the control and set the location of the control to the current mouse coordinates.

That’s all it was. Now you could add persistence in the form load and form close for the controls and nothing stands in the way of the user designing the forms.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: