Lukas Bystricky
Lukas Bystricky

Reputation: 1272

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?

Upvotes: 5

Views: 13673

Answers (3)

Hans Passant
Hans Passant

Reputation: 941377

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.

Upvotes: 3

Praveen VR
Praveen VR

Reputation: 1564

Try this:

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

Upvotes: 0

spirosvp
spirosvp

Reputation: 130

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);
    }

Upvotes: 4

Related Questions