Windows Develop Bookmark and Share   
 index > Windows Forms Designer > snap form to control
 

snap form to control

Is there a way to snap a parentform to a childcontrol? Of course it works the other way around, but I hate to be inconsistent and I need all my margins to have the same size.

Hope I made myself clear.

Thanks

levelupl0x  Sunday, July 19, 2009 7:52 PM

Hi levelupl0x,

Based on my understanding, you want the controls on the form anchor to some edges. For example, there are three buttons on your form. You want the distance between each button and the right/bottom edge of the form would not be changed while you are resizing the form. You can achieve your goal by setting the Anchor property of each control to 'Bottom, Right'. You can do it in designer or follow this code snippet:
this.button1.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
  • Marked As Answer bylevelupl0x Tuesday, July 21, 2009 7:02 AM
  •  
Aland Li  Tuesday, July 21, 2009 6:10 AM

Hi levelupl0x,

Do you mean capturing the image of the form to a control?

Best regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Tuesday, July 21, 2009 3:22 AM
Hi Aland Li,

what I meant was, when I resize a form, it should snap to the nearest control and respect it's set margin. Here's a screenshot.

That is, a control snaps to a form's edges when moved around, but a form does not snap to a control's edge when resized. The only way to achieve consistent edge space, is

1. Resize form
2. Move controls in form so that they again"snap" to their set margin (usually 3px)

I want to do(1) without (2). I want it to be pixel-perfect.

Does that makes sense? Is it even possible?

Thanks :)
levelupl0x  Tuesday, July 21, 2009 5:56 AM

Hi levelupl0x,

Based on my understanding, you want the controls on the form anchor to some edges. For example, there are three buttons on your form. You want the distance between each button and the right/bottom edge of the form would not be changed while you are resizing the form. You can achieve your goal by setting the Anchor property of each control to 'Bottom, Right'. You can do it in designer or follow this code snippet:
this.button1.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
  • Marked As Answer bylevelupl0x Tuesday, July 21, 2009 7:02 AM
  •  
Aland Li  Tuesday, July 21, 2009 6:10 AM

Hi levelupl0x,

Could you please let me know if my reply helps you? If you still have problems, please feel free to tell me.

Regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Tuesday, July 21, 2009 6:53 AM
Hi Aland Li,

that worked perfectly!

Thanks again
levelupl0x  Tuesday, July 21, 2009 7:02 AM

You can use google to search for other answers

Custom Search

More Threads

• inherited controls
• Custom Control and Properties Tab
• Rounded form edges
• Custom Combo box control
• problem with ListView's SelectedIndexChanged
• How to allow resizing in one direction only?
• Generating dynamic columns on a designer generated DataGridView control
• Disable scroll bars in a mdicontainer form
• Can no longer drag Container-type controls with mouse in IDE
• pls help: Resize control at runtime?