Search | Contact | Link To Us  

      VB .NET       

.NET Defined
OOP with VB
VB Language
Win Forms
Windows Controls
ADO .NET
User Controls
File Handling
Multithreading
Deployment
XML Web Services Essential XML
Resources
Discussions
ASP.NET
About



Advertisement


































































     Home> Forms> Anchoring and Docking 


Anchoring and Docking Controls

Anchoring and Docking is used to make controls cover the whole client area of a form.

Anchoring

Anchoring is used to resize controls dynamically with the form. If you are designing a form that the user can resize at run time then the controls on your form should resize and reposition properly. The Anchor property defines an anchor position for the control. When a control is anchored to a form and the form is resized, the control maintains the distance between the control and the anchor positions.

Anchoring a control

To anchor a control, first select the control. In the Properties window select Anchor property. Selecting that displays an editor that shows a cross. To set an anchor, click the top, left, right, or bottom section of the cross. By default controls are anchored to the top and left side. To clear a side of the control that has been anchored click that side of the cross. When your run the form the control resizes to remain positioned at the same distance from the edge of the form. The distance from the anchored edge always remains the same as the distance defined when the control is positioned during design time. The image below demonstrates that.

Docking

When you dock a control, it adheres to the edges of its container (form). To dock a control, select the Dock property of that control from the properties window. Selecting the dock property opens up a small editor from which you can select to which side on the form should the control be docked.

Docking a control

Select the control that you want to dock. In the Properties window select Dock property. An editor is displayed that shows a series of boxes representing the edges and the center of the form. Click the button that represents the edge of the form where you want to dock the control. To fill the contents of the control's form or container control, click the center box. The control is automatically resized to fit the boundaries of the docked edge.

Working with Example

The following three images will demonstrate Anchoring and Docking. The image below is a form with a TextBox on it.

Anchoring

The image below displays the TextBox anchored to top-right side of the form. From the image you can view the TextBox maintaining the same distance from the top and right sides of the form when the form is increased in size.

Anchoring

Docking

The image below displays the TextBox docked towards the bottom of the form.

Docking

Windows Forms Opacity

A beautiful feature of Windows Forms is Opacity. The Opacity property is used to make a form transparent. To set this property set the Opacity property to a value between 0 (complete transparency) and 100 (complete opacity) in the properties window. The Image below demonstrates Opacity property. The form is set to an opacity value of 75.

Transparent forms are only supported in Windows 2000 or later. Windows Forms will be completely opaque when run on older operating systems such as Windows 98/95 regardless of the value set for the Opacity property.

  Privacy Policy | Terms of Use | Site Map | Contact

  © 2004-2010 Startvbdotnet.com. All rights reserved.