Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically (only) resizable windows form in C#

I have a situation where it would be beneficial to me to allow my windows form to be resized by the user, but only vertically. After some searching, it seems like there isn't much on this particular subject. Is it possible?

like image 748
Ben Avatar asked Jan 26 '10 16:01

Ben


People also ask

How do you make a windows form resizable?

To make a control resize with the form, set the Anchor to all four sides, or set Dock to Fill . It's fairly intuitive once you start using it. For example, if you have OK/Cancel buttons in the lower right of your dialog, set the Anchor property to Bottom and Right to have them drag properly on the form.

Is it possible to resize a control within the form design window?

You can resize individual controls, and you can resize multiple controls of the same or different kind, such as Button and GroupBox controls.

How do I stop winform from resizing?

Resizing of the form can be disabled by setting the FormBorderStyle property of the form to `FixedDialog`, `FixedSingle`, or `Fixed3D`.

What is the use of AutoSize Property in Visual basic?

Use AutoSize to force a form to resize to fit its contents. A form does not automatically resize in the Visual Studio forms designer, regardless of the values of the AutoSize and AutoSizeMode properties. The form correctly resizes itself at run time according to the values of these two properties.


1 Answers

You need to set the form's MinimumSize and MaximumSize properties to two sizes with different heights but equal widths.

If you don't want the horizontal resize cursor to appear at all, you'll need to handle the WM_NCHITTEST message, like this:

protected override void WndProc(ref Message m) {     base.WndProc(ref m);     switch (m.Msg) {         case 0x84: //WM_NCHITTEST             var result = (HitTest)m.Result.ToInt32();             if (result == HitTest.Left || result == HitTest.Right)                 m.Result = new IntPtr((int)HitTest.Caption);             if (result == HitTest.TopLeft || result == HitTest.TopRight)                 m.Result = new IntPtr((int)HitTest.Top);             if (result == HitTest.BottomLeft || result == HitTest.BottomRight)                 m.Result = new IntPtr((int)HitTest.Bottom);              break;     } } enum HitTest {     Caption = 2,     Transparent = -1,     Nowhere = 0,     Client = 1,     Left = 10,     Right = 11,     Top = 12,     TopLeft = 13,     TopRight = 14,     Bottom = 15,     BottomLeft = 16,     BottomRight = 17,     Border = 18 } 
like image 55
SLaks Avatar answered Sep 19 '22 15:09

SLaks