[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Expand]Build an Application
 [Expand]Controls and Libraries
 [Collapse]Common Features
  [Expand]Data Binding Common Concepts
  [Expand]Data Source Wizard
    File and Folder Browser Behaviors
    Persistence Behavior
    Indicator Behaviors
    Stub Glyph Behavior
    Banner Behavior
    Breadcrumb Behavior
    Disabled Cell Behavior
    Drag-and-Drop Behavior
    Magnifier Behavior
    Pager Navigation Behavior
    Scrollbar Annotation Behavior
    Snap Window Behavior
  [Expand]Application Appearance and Skin Colors
  [Expand]Filtering UI Context
   Find Panel Syntax
  [Expand]Graphics Performance and High DPI
  [Expand]Scaffolding Wizard
  [Expand]Formatting Values
   HTML-inspired Text Formatting
  [Expand]Save and Restore Layouts
   Clipboard - Copy and Paste Operations. Data Formatting
   Version Compatibility: Default Property Values
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Snap Window Behavior

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

  • SnapToScreen - specifies whether or not the target control can snap to screen edges.
  • SnapToControls - specifies whether or not the target control can snap to other snap objects (see below).
  • SnapThreshold - when a distance in pixels between a target control and a snap zone reaches this value, the target control will be snapped.
  • SnapOnMoving - if enabled, the target control will snap to available snap regions on the move (when end-users drag this control).
  • SnapOnResizing - if enabled, the target control will snap to available snap regions when end-users resize it.

Expanded Enable Window Snapping for Separate Forms

When you attach a snap window behavior to any standard or DevExpress form, you actually do two things:

  • provide this form with a variety of options that specify how and when this form itself will be able to snap;
  • declare this form as a snap zone to which other sticky forms can snap (if their own behavior options allow them so).

Based on these two statements, the following is true.

  • A form that is the only one with a snap window behavior attached can by default snap only to screen edges, since no other snap zones are present.
  • To be able to snap multiple forms to each other, attach a behavior to each one of them.
  • You can attach a snap window behavior to a form and disable all of its snapping options. In this case, the form will not be able to snap anywhere. However, other sticky forms will still recognize it as a snap zone and will be able to snap to it.

Expanded Provide Custom Snap Zones For Sticky Windows

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.

Is this topic helpful?​​​​​​​