8.25 Anchoring Controls

 <  Day Day Up  >  

You want your controls to automatically size as the size of your main Windows Form changes.


Technique

Select the control within the forms designer that you want to anchor and click on the anchor editor accessible through the Anchor property. You see a small UI Type Editor, as shown in Figure 8.9. There are four possible anchor points for a control, corresponding to the top, left, bottom, and right sides of the Windows Form. When the anchor point is dark, the control is anchored to the corresponding anchor point on the form. By default, all controls are anchored to the top and left sides of a form.

Figure 8.9. The anchor editor allows you to select the edges of a form to anchor the edges of a control to.

graphics/08fig09.jpg

Comments

The Anchor property is defined in the base class System.Windows.Forms.Control , which means it is accessible in Windows Forms controls. By setting this property, you can be sure that when the user resizes the Windows Form, the controls also resize in response to maintain a consistent user interface. Based on which side or sides a control is anchored to, it does one of two things in response to a form resize. If only a single side of opposite sides is anchored ”the left but not right side, for example ”then the control's position changes in the Windows Form. However, if both competing sides are anchored, then the control resizes itself but stays in the same location. Therefore, if you want a control to cover the entire width of a form, you want to specify a left- and right-side anchor. If instead you would rather have a control stay the same size but remain pinned to the right side of a form, then only specify a right-side anchor. Furthermore, if you have a control that should cover the entire form, which is the case for many document-based interfaces such as Notepad, then you should anchor all sides of the control. This step ensures that the control is properly resized when the user increases both the width and height of a Windows Form.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net