VCL Forms that snap to the edge of the screen

I was just reading this article over on delphi.about.com about getting forms to snap to the edges of the screen. Since at least Delphi 7 this functionality has been built into the VCL and is available through two properties on TCustomForm called ScreenSnap and SnapBuffer.

  • ScreenSnap is a boolean and toggles the feature on/off.
  • SnapBuffer is the distance in pixels from the edge of the screen that you want snapping to occur, the default is 10 pixels.

3 thoughts on “VCL Forms that snap to the edge of the screen

  1. This is cool to have in the VCL, but as far as I know it doesn’t snap to other forms or windows, only the screen edges. So someone who wants form snapping still has to implement half of it.
    (Not that I’m complaining, even half is good! It’s a nice inbuilt feature.)

  2. Hi David,
    The other "half" (in your words) has been written it’s just that some interesting issues arise when you start allowing forms to snap to one another like what happens when you drag or resize the snapped forms. Until we satisfactorily work through those issues that probably won’t surface in the core VCL.
    -Steve

  3. Hi, the Snap function in Delphi is buggy! Yea!
    Just do this simple exercise: Put your TaskBar on the Right or on the Top of your Screen, and try to snap to them. It won’t work.
    The inside code shipped in Delphi 7 is:
    HandleEdge(x, Left, Monitor.WorkareaRect.Left);
    HandleEdge(y, Top, Monitor.WorkareaRect.Top);
    HandleEdge(x, Right, Width);
    HandleEdge(y, Bottom, Height);
    But it should be:
    HandleEdge(x, Left, 0);
    HandleEdge(y, Top, 0);
    HandleEdge(x, Right, Width);
    HandleEdge(y, Bottom, Height);
    Greetings!!

Comments are closed.