Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Designing Resizable Windows Forms in Visual Studio .NET

Are you sick of wasting time writing resizing code for your Windows forms? .NET's new anchoring and docking properties enable form controls to automatically resize or reposition themselves as the form resizes. This article explains how to create resizable Windows forms automatically, or with just a few lines of code.


advertisement
Most of you have heard of—and probably used—the new anchoring and docking properties available to Windows form controls. They enable controls to automatically resize or reposition themselves as the form resizes. This saves time that would normally be spent writing inane, non-productive resizing code just to make the forms look the same. This article explains how to use the new properties to save yourself some coding time.

Docking
The Docking feature attaches a control to the edge of its container. When a control is docked to an edge of it's container, it will always stick to that edge. The control will also resize itself to fully fit the edge of the container and also resizes as the container is resized. The Dock property of the Form control can be set to any one of the six values, Top, Bottom, Left, Right, Fill, and None.

By default the Dock property is set to None. To graphically set the Dock property, click on the dropdown at the right of the Dock property in the Properties window. Then, select the edge to which you want to dock the control, or dock it to the center (Fill) or set to None.



Controls can also be docked by code:

' VB.NET Me.Button1.Dock = System.Windows.Forms.DockStyle.Left //C# this.button1.Dock = System.Windows.Forms.DockStyle.Left;