Honesty Rocks! truth rules.

How To Make A Window Form Smooth Snap To Desktop Edge ?

HOME      >>       Programming


Hi, All, Now I got another issues that I wanted to implment a window that will snap to desktop edge.What I'am do now was creating it with timer and some windows api to check positionssay if within a range then move the form window to any edge.But this has an issue with it the window will flicker.Any ideas with this issue ?Thanks,---Magiccode9


Why not listen for Form.Move event, since you would only want to snap the form when it's moving right?

Then in the event handler just compare Form.Bound against Screen.PrimaryScreen.Bounds. Do take into consideration of pc with multiple display.

Btw, if you just need this feature for your own use, take a look at Pitaschio. It does what you're looking for to all windows and form, plus added some more great features, good for daily use.


Faulty, Thanks your help !I have been tested it with Form.Move event and related bounds.But this still has flicker when I assign the top property of a form to 0.Also, I have found a vb6 sample that does somethings similar to what I want to do.That is a sample that restricted a window won't over the screen bound with a smooth moving.With this example, it is much harder to get it works.It basically work with windows message directly by intercept some messages.I'am looking for this to see how it work.Actually, it is used for my own small app that I build to get RSS feed and store some structure data.I still looking for some sample code for this.Thanks,P.S. I'am using the RapidTools as a reference.---Magiccode9


Have you try to enable doublebuffering?
Do this inside your form's constructor after InitializeComponent()

this.SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer,true);