Code Monkey home page Code Monkey logo

stickywindows's Introduction

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

stickywindows's People

Contributors

thoemmi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.