Guides in Windows Forms Diagram
Guides for the WinForms Diagram control are viewable, non-printing guidelines used to align a diagram node with other nodes. They provide support to align a diagram node with the boundary, center, or margin of other nodes. Guides are rendered only while dragging or resizing a node; they are not shown in the static diagram view and are not included when the diagram is printed.
You can also change the visual style of the guides by using its LineStyle property.
Properties
The following table describes the various properties associated with the Guides class:
| Property Name | Description |
|---|---|
| Gets the Diagram Guides object. | |
| Enables or disables the diagram guides. | |
| Gets or sets the visual style for the diagram guides. | |
|
Specifies the guide type for nodes. The available
options are: Boundary Center Margin All . When `Margin` is set, the `Margin` property value is used to draw the margin line between nodes. |
|
| Gets or sets the margin between nodes, in pixels (float). |
Enable and Customize Guides
The following code example illustrates how to turn on guides for diagram nodes while dragging or resizing nodes. A Diagram control named diagram1 must already exist on the form.
// Turns on guides in the diagram.
diagram1.Controller.Guides.Enable = true;
// Shows all types of guides.
diagram1.Controller.Guides.Type = GuideTypes.All;
// Specifies the line color for guides.
diagram1.Controller.Guides.LineStyle.LineColor = Color.FromArgb(255, 153, 51);
// Sets the margin between nodes.
diagram1.Controller.Guides.Margin = 50;'Turns on guides in the diagram.
diagram1.Controller.Guides.Enable = True
'Shows all types of guides.
diagram1.Controller.Guides.Type = GuideTypes.All
'Specifies the line color for guides.
diagram1.Controller.Guides.LineStyle.LineColor = Color.FromArgb(255, 153, 51)
'Sets the margin between nodes.
diagram1.Controller.Guides.Margin = 50The following screenshot shows the guides rendered while dragging a node:
