Represents the horizontal and vertical line segments that are dynamically created in the user interface (UI) to assist in the design-time layout of controls in a container. This class cannot be inherited.
See Also: SnapLine Members
The following table lists the common modes that visual design tools support to assist you with positioning and sizing controls on a design surface.
Freeform |
Enables you to freely lay out controls. |
Grid |
Displays a static overlaid grid that assists you in laying out controls. |
Snapline |
Displays guide lines that assist you in laying out the container's controls relative to each other. Snaplines originate from controls and their container. |
The System.Windows.Forms.Design.Behavior.SnapLine class and related types help support the Snapline mode.
Snaplines are generated dynamically and automatically as a control edge moves near another control or near the boundaries of its container. This can occur when a control is added from the toolbox, or moved or resized by mouse operations or keyboard commands. Controls typically have both horizontal and vertical snaplines defined; for rectangular controls, these typically extend from all four edges.
The System.Windows.Forms.Design.Behavior.SnapLine class uses only a few properties to describe each snapline, as shown in the following table.
SnapLine.SnapLineType |
Specifies the location and direction of the line with respect to its associated control. Typically, only snaplines of similar types will auto-align to each other. |
SnapLine.Offset |
Specifies the distance in pixels from the origin, which is the upper-left corner of the control, to where the snapline starts. |
SnapLine.Priority |
Specifies the relative importance of the snapline. During any given layout decision point, only the snaplines that are active and have the highest priority are displayed. |
SnapLine.Filter |
Defines custom categories of snaplines. This is an optional string. |
SnapLine.IsHorizontal and SnapLine.IsVertical |
Indicates whether a snapline has horizontal or vertical orientation, respectively. |
The System.Windows.Forms.Design.ControlDesigner class stores snaplines for its corresponding control type in the System.Windows.Forms.Design.ControlDesigner.SnapLines property. This base class handling of snaplines will suffice for the majority of controls, as it defines the SnapLineType.Left, SnapLineType.Right, SnapLineType.Top, and SnapLineType.Bottom snaplines, which are aligned along the edges of the control. When you are developing a custom control, if this default organization does not suffice, override the System.Windows.Forms.Design.ControlDesigner.SnapLines property of the class derived from System.Windows.Forms.Design.ControlDesigner. For example, you may want to align the horizontal snaplines of text-based controls, such as labels, with the top and base lines of the text (instead of the top and bottom edges of the control).
The SnapLine.SnapLineType class cannot be derived from.
There is extensive support for this feature in Visual Studio.
dl_WalkthroughArrangingControlsWindowsFormsUsingSnaplines