简体   繁体   中英

Set form minimum size

I have a C# form with a sizable border. I'd like to set the minimum size to (850, 760) (the default starting size), but when I try to set the value in the form properties menu it keeps changing it to (850, 720). I tried setting it by code as follows:

this.minimumSize = new System.Drawing.Size(850, 760);

but when I run the code I can still shrink my form vertically. Does anyone have any ideas as to what the problem might be?

EDIT: I'm using two monitors, one standard 1280x1024 and the other widescreen 1366x768, could that be the problem? In that case is there some way to test the user's monitor resolution and set the minimum size based on that?

A lot of the code that runs at runtime is active at design time as well. That gives the Winforms designer a very nice WYSIWYG user interface, but it does have some unfortunate side-effects. Including crashing the designer and giving you the White Screen of Darn. Or crashing VS to the desktop if you trip this website's name.

This is one such side-effect, the runtime code limits the MinimumSize to the Screen.WorkingArea and does so at design time as well. Just try typing in (0, 3000) to see that happening. You can force it by assigning the property in code.

I think you should look your code again.It should look like this in the designer or the page_load of your form.

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.Text = "Form1";
        this.MinimumSize = new Size(300,300);
    }

Try this:

Set FormBorderStyle property of form to FixedSingle . Then form border resizing will be disabled

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM