Working with Windows Forms, I wonder if there is some way to prevent vertically resize of the form. I would like to allow user to resize a form in all directions except vertically. Moreover, I would like to allow vertically resize in the upward direction, but not downward.
I have tried to use maximumsize by setting it to: Me.maximumsize = new size(0, me.height)
I set width to 0, because I want to allow user to change the form width.
Unfortunately it doesn't work.
Any ideas?
Best Answer
You have to be careful to allow the form to resize itself at startup. It is necessary to accommodate scaling needed on a machine that has a different video DPI setting or a different system font size. Or a user override that changed the height of the title bar. All of this is sorted out by the time the Load event runs. Thus:
The next thing you ought to do is fix the behavior of the cursor when the user moves it on an edge of the window that allows resizing the window vertically. That's a bit ugly; you have to trap the WM_NCHITTEST message with WndProc and change the message return value: