Width not changing when Size changes

2019-07-20 21:16发布

问题:

I've been doing this for years. But now it's just not working.

private void Form1_Deactivate(object sender, EventArgs e)
        {
            this.Size = new Size(30, 29);
            txt.Visible = false;
            lbl.Visible = false;
        }

The form just does not change Width. But, as above, the 3 controls DO become invisible.

Any suggestions?

回答1:

Windows have an absolute minimum width of 134 pixels (at least on Windows 7)

To circumvent this minimum, you can set FormBorderStyle to FixedToolWindow or SizableToolWindow. (Or handle Windows messages)



回答2:

First set the FormBorderStyle to SizableToolWindow then set your own value.