Make resizing snap to certain widths of a Window

1k views Asked by At

Background: I have a window that starts out with a width of 240px, some visual elements can only be displayed a particular way at this width, however resizing is allowed and must be allowed.

If someone decides to resize, then i will need some sort of "Snap" to get back to the original width. It would be a pain/next to impossible to require the users to get the exact px right in order to restore full visual effects.

Question: So, how can i make it so if they get to a certain distance (lets say, within 4px) away from 240px in either direction, it will snap to that width, and resize to a different size only when the resize cursor has strayed over 4px away from the width..

Failed Ideas: ive played with several different things that set the width of the window to 240 on the sizeChanged event if its within the 4px, but since that is on the size event, it will do the calculations after the window has already resized. which means that you get a really choppy effect when it is being resized to/away from the default width.

1

There are 1 answers

1
Rick Sladkey On BEST ANSWER

Here is a message that explains how to gain fine-grained control over the resizing by handling the WM_SIZING message in your own window procedure:

The moderator's sample code is in VB but there are plenty of C#/WinForms examples you can use to get started.