windowsforms-117319-common-features-behaviors-snap-window-behavior.md
The Snap Window Behavior allows you to implement sticky windows that snap to other windows and screen edges.
The behavior also supports custom snap zones, which means you can manually specify regions to which your sticky windows should be able to snap.
Supported controls
Behavior options
When you attach a snap window behavior to any standard or DevExpress form, you actually do two things:
Based on these two statements, the following is true.
Default snapping options allow sticky windows to snap to screen edges and other windows of their kind. You can also supply sticky windows with custom snap zones to which these windows will be able to snap.
The animation below illustrates a sample: main form contains four labels that act as custom snap zones. The child form is able to snap to these custom zones.
To make this setup work, do the following.
Define rectangular snap zones to which sticky windows will be able to snap. In this sample scenario, snap zones match the label controls’ bounds. Same bounds can be used to draw dashed borders around labels to clearly visualize them as snap zones.
In the host form’s code, define public properties that will allow you to retrieve snap zones from outside. Call the Control.PointToScreen method to retrieve screen coordinates instead of form coordinates.
Retrieve the default snap window helper and customize its snap zone collection. To do so, access the static Default property of the DevExpress.Utils.Controls.SnapWindowHelper class and handle its QuerySnapRectangles event. In the event handler, modify the QuerySnapRectanglesEventArgs.CustomRectangles collection as required.