Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Width of the form can not be less than 140 pixels. Why?

Tags:

c#

width

winforms

I created default Windows Forms Application project in Visual Studio 2012. When I run program then saw that width of form can not be less than 140 pixels. Why? And how to overcome this strange restriction?

like image 580
Anatolii Humennyi Avatar asked Aug 28 '13 21:08

Anatolii Humennyi


3 Answers

I was looking for a solution and MinimumSize(0,0) didn't had any effect. Figured out, that MinimumSize set to (1,1) actually fixed the problem and after showing my form it was properly sized smaller than 140px.

Column click event on (ListView)_csvLv that should trigger a popup dialog:

        var topAnchor = _csvLv.PointToScreen(new Point(
            _csvLv
                .Columns
                .OfType<ColumnHeader>()
                .Where(c => c.DisplayIndex < e.Column)
                .Sum(c => c.Width),
            0));

        Left = topAnchor.X;
        Top = topAnchor.Y;

        MinimumSize = new Size(1,1);
        ClientSize = new Size(_csvLv.Columns[e.Column].Width, 100);

        ShowDialog();
like image 57
Code Guru Avatar answered Oct 03 '22 15:10

Code Guru


Users wouldn't be able to use the window's minimize, maximize, and close buttons at that top. I don't believe you can change that behaviour with the Sizable FormBorderStyle. It's a usability thing.

If you remove the border, by setting it to None for example, you can set it to whatever you want programmatically by doing:

form.Width = [...];

You can resize further forms with border types: None, FixedToolWindow, and SizableToolWindow. The ToolWindows won't let you go below a certain amount as well, but None will let you do anything above 2px. You could set it to some value below that, without getting an exception, but it won't do anything.

like image 30
Marc-Antoine Beaulieu Avatar answered Oct 03 '22 17:10

Marc-Antoine Beaulieu


Try this. Autosize no AutosizeMode growOnly FormBorderStyle SizableToolWindow <== this one did it I still can move the form and resize it (width) less tan 112

like image 33
Saverio Avatar answered Oct 03 '22 15:10

Saverio