Skip to Content
Programming Visual Basic .NET
book

Programming Visual Basic .NET

by Dave Grundgeiger
December 2001
Beginner
464 pages
13h 51m
English
O'Reilly Media, Inc.
Content preview from Programming Visual Basic .NET

Form and Control Layout

Windows Forms allows developers to lay out sophisticated user interfaces that are capable of intelligently resizing without writing a line of code. Previously, developers writing desktop applications for Windows typically spent a good deal of time writing resizing code to handle the placement of controls on the form when the user resized the form. The .NET platform, however, allows you to define a control’s layout and size by setting a few properties.

The Anchor Property

The Anchor property lets a control anchor to any or all sides of its container. Each anchored side of the control is kept within a constant distance from the corresponding side of its container. When the container is resized, its anchored controls are repositioned and resized as necessary to enforce this rule. The Anchor property is defined by the Control class (in the System.Windows.Forms namespace) and so is inherited by all controls and forms. Its syntax is:

Public Overridable Property Anchor(  ) As System.Windows.Forms.AnchorStyles

The AnchorStyles type is an enumeration that defines the values Left, Top, Right, Bottom, and None. To anchor a control on more than one edge, combine the values with the Or operator, as shown here:

' Assumes Imports System.Windows.Forms
SomeControl.Anchor = AnchorStyles.Top Or AnchorStyles.Right

By default, controls are anchored on the top and left sides. This means that if a form is resized, its controls maintain a constant distance from the top and left ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Visual Basic .NET, Second Edition

Programming Visual Basic .NET, Second Edition

Jesse Liberty

Publisher Resources

ISBN: 0596000936Supplemental ContentCatalog PageErrata