Share via


Snaplines

Click here for larger image

The Windows Forms 2.0 designer has a new alignment paradigm for placing controls. Dynamically generated snaplines are now used to lay out controls on the design surface.

When a control is placed on a form at design time, it offers up interesting alignment points. These points typically include the edges, margins and text baseline of the control. As another control is moved towards the first, a snapline is drawn between matching interesting points. This allows developers to quickly place controls.

One of the driving scenarios for snaplines was to line up text baselines of controls. As the picture above shows, the red snapline aligns the text baseline of the Label to the baseline on the TextBox.

In Windows Forms 2.0 all controls have a margins property. This is the amount of distance around a control. When two controls are moved close to one another, a snapline is offered at the sum of their margins. This is the distance that UI guidelines recommend the controls are separated.

Similarly, containers have a new property called padding. This is the inward distance from the container’s edge controls should be placed. Snaplines are also generated as a control approaches a container’s margins.

Snaplines are offered not only on mouse moves, but when controls are added from the toolbox and on control resize. If a control is moved with the control key and an arrow key, then the control moves to the next snapline in that direction.

Control authors can also define custom snaplines for their controls. This is exposed via the virtual SnapLines property on ControlDesigner.