Skip to content

Make your top-level windows stick when moved or resized.

License

Notifications You must be signed in to change notification settings

thoemmi/StickyWindows

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StickyWindows

This library helps creating window applications where the windows can both stick to screen borders and to each other.

The code originates from the Codeproject article Sticky Windows - How to make your (top-level) forms to stick one to the other or to the screen by Corneliu Tusnea. He never published a NuGet package, so I asked for his permission to both create a repository at GiutHub and publish it as a NuGet package.

Build status and NuGet packages

Stable Pre-release
AppVeyor Build status Build status
StickyWindows NuGet NuGet
StickyWindows.Wpf NuGet NuGet

Usage

Actually there are two libraries published: one is for WinForms applications, and the other one for WPF applications. The latter bases on the WinForms package though. but this shouldn't be an issue as that the WinForms library is part of the .NET framework and as such is always available.

WinForms

For WinForms application, use the StickyWindow package.

In the constructor of your form add this line:

new StickyWindows.StickyWindow(this);

If you want to deviate from the default settings, StickyWindow provides following boolean properties (which are all true by default:

  • StickOnMove
    Allows the form to try to stick when the form is moved.
  • StickOnResize
    Allows the form to try to stick when the form is resized.
  • StickToOther
    Allows the form to try to stick to other stick-able forms.
  • StickToScreen
    Allows the form to try to stick to the screen margins.

WPF

For WinForms application, use the StickyWindow.WPF package.

You have two options to make your windows "sticky":

  1. Subscribe to your window's Loaded event and call the extension method CreateStickyWindow in the handler:

    _stickyWindow = this.CreateStickyWindow();
  2. Use the StickyWindowBehavior in your XAML code (which I think is more elegant than option 1):

     <Window
       x:Class="WpfTest.Window2"
       xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
       xmlns:wpf="clr-namespace:StickyWindows.WPF;assembly=StickyWindows.WPF"
       ...>
       <i:Interaction.Behaviors>
         <wpf:StickyWindowBehavior />
       </i:Interaction.Behaviors>
       ...
     </Window>

Both options support the same properties as the WinForms implementation.

Please note that StickyWindows.WPF requires System.Windows.Interactivity, which is neither part of the library nor a dependency of the NuGet package. The point is, there's no official NuGet package for System.Windows.Interactivity by Microsoft. I decided against delivering this library as part of StickyWindows.WPF as it may conflict with different versions in other libraries you may be using potentially.

Version History

v0.3 (not released yet)

  • Fixed the MaximumSize and MinimumSize issue reported in #5 (Thanks to @lucky3)
  • Added SourceLink support

v0.2 (11-Apr-2017)

  • Fixed strange margin when running on Windows 10 (#1)

v0.1 (10-Mar-2017)

  • Inital Release

About

Make your top-level windows stick when moved or resized.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages