How to make my Windows Form app snap to screen edges?

This worked pretty well, works on multiple monitors, observes the taskbar: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private const int SnapDist = 100; private bool DoSnap(int pos, int edge) { int delta = pos - edge; return delta > 0 && delta Location); if (DoSnap(this. Left, scn.WorkingArea. Left)) this.

Left= scn.WorkingArea. Left; if (DoSnap(this. Top, scn.WorkingArea.

Top)) this. Top = scn.WorkingArea. Top; if (DoSnap(scn.WorkingArea.

Right, this. Right)) this. Left = scn.WorkingArea.

Right - this. Width; if (DoSnap(scn.WorkingArea. Bottom, this.

Bottom)) this. Top = scn.WorkingArea. Bottom - this.

Height; } }.

Just retrieve the current pixel height/width of the monitor you're on... stackoverflow.com/questions/229528/how-t... ... and process the location changed/moved events for the form. When you get within, say 25 pixels or so of an edge (your main form's Location. Left + form width) or height (your main form's Location.

Top + form height), then go ahead and set the . Left and . Top properties so that your application "docks" in the corners.

Edit: One other note - when you actually do the "snapping" you may also want to move the cursor position the relative distance to make it stay on the same point on the window bar. Otherwise your form may become a giant ping pong ball between the cursor position and your "snappy" functionality as the MouseMove and form location changed events fight against each other.

The only problem with that is once your docked you can never leave. Be sure to allow for a mouse move, (i.e. Click and drag 25 pixels) once docked that can undock your form.

– Neil N Feb 26 '09 at 6:03 2 If that were desired functionality, you could call it a "Docking Hotel California". – routeNpingme Feb 26 '09 at 6:06 1 Don't you think you should allow for the taskbar and other toolbars rather than obscuring them? – MarkJ Feb 26 '09 at 9:16.

I don't know if you found your solution, but I created a small component for just that: formsnapper.net - it snaps accross the process boundaries!

How To Make My Windows 7 Wallpaper - YouTube.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions