views:

157

answers:

3

C#: How can I move my controls on a win form in windows application freely?

I do NOT want IDE control the position of my controls for me.

Thank you

A: 

Do you mean at runtime dragging the controls around?

If so: you have to check when the mouse is clicked, find the control, and move it around on drag as long as the button is clicked.

Snake
No, In design time, it seems that I can't set the position of a label properly near to its related text box. It seems that IDE has a pattern to set the position of controls.. I turned "Snap to Grid" property off but I still have my problem.
odiseh
A: 

it seems u r looking for similar implementation as in visual studio forms designer. system.design assembly defines DesignSurface that can certainly do what u need. check this out.

http://www.codeproject.com/KB/cs/DesignSurfaceExtended.aspx

this. __curious_geek
+2  A: 

Visual Studio tries to help you align your controls by "snapping" them to an alignment line (e.g. left of another control, right of another control, a short distance from another control or the form edge etc.), so this might be what you experience as not being able to move your controls freely?

If this is the case, you can fine-tune the position by using the arrows on your keyboard. Move the control approximately where you want it with your mouse, and then use the keyboard for the final adjustment.

Nailuj
Also, a small tip I forgot to mention: after you have made your form just as you want it, right-click and choose "Lock Controls" to prevent you from accidentally moving something around at a later point :)
Nailuj