1

From my own research this does not seem to fall into the same category as the DPI situation for which it is said to be a duplicate. This situation is clearly a result of the settings of the "AutoScaleMode" and "Font" properties as I mention below !

I've recently started writing some code in C# using Visual Studio 2017. I have a form that I do not want to be resized any smaller than a certain size. Using the property view I set the form's MinimumSize property to that size and yet when I run it I am able to resize it to a smaller size. It does however have a limit I just don't know how it determines that limit. Am I missing something here?

So I tried a simple form program:

  • One form
  • Form size minimum set to 500 x 500
  • Form original size set to 500 x 500
  • One label on the form
  • One handler that writes the size of the form to the label on a resize

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_ResizeEnd(object sender, EventArgs e)
        {
            Size sz = this.Size;
            label1.Text = sz.Width + "x" + sz.Height;
        }
    }
}

And when I run this, it starts out at something like 324x232. I am able to resize this all the way down to 198x232. I don't understand. Can somebody please expalain?

Cyberclops
  • 311
  • 2
  • 17
  • 1
    Clearly, the form on the screen doesn't have those MinimumSize settings. – LarsTech Jul 24 '18 at 18:40
  • What happens if you add a label that displays the MinimumSize? – BJ Myers Jul 24 '18 at 18:43
  • 1
    Show the relevant portion of your form designer file where you set the minimum size. This feature has always worked for me. – Dan Wilson Jul 24 '18 at 18:43
  • I'm not seeing what you are seeing - I see a 500x500 form that can be stretched, but not shrunk below 500x500. The only difference is that I set the label's text in `Form1_SizeChanged` handler rather than the `ResizeEnd` handler. I do remember from User32/GDI32 programming that there's a rather intricate dance of events during a resize. Perhaps your ResizeEnd handler is getting in the way. – Flydog57 Jul 24 '18 at 18:47
  • For what it's worth, if I set the MinimumSize property in the VS WinForms designer (VS 2017), the Size property jumps up to that size (if it was less than the minimum size). Do you actually have `this.MinimumSize = new System.Drawing.Size(500, 500);` in your Form1.Designer.cs file? – Flydog57 Jul 24 '18 at 18:57

1 Answers1

1

So I figured out why the minimum size was not what I figured it to be ...

On the form there is another property called "AutoScaleMode". If this is set to font then the whole form is scaled by the size of the font selected in the Font property. In my case the Font property was set to "Microsoft San Serfi 8.1pt". Changing this setting to bigger or smaller fonts scaled the forms minimum size up or down accordingly. The other setting for the AutoScaleMode property are "None", "Dpi", and "Inherit". I'll have to study a bit to figure out exactly how all of these work, but suffice it to say that setting it to "None" yielded the results I expected. I'm just not sure how that will affect the form in other aspects of its operation.

Cyberclops
  • 311
  • 2
  • 17