Minimum Form Width

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

If you create a new Windows Forms application in Visual Studio 2005
you'll get a project with a single form with FormBorderStyle =
Sizeable. In the designer if you drag the right edge of the form and
try to make the form as narrow as possible the form width will reduce
to 123 pixels (on my system) and then can't be reduced further. What
is controlling this?

I'm developing a toolbar based apoplication and the toolbar has to
optionally small and vertically oriented. I'm finding I can't reduce
the width below a certain point and I need to be able to do this.
I've tried setting AutoscaleMode = None and MinimumSize = (0,0) but I
can't reduce the width below 123 pixels.

Can someone tell me how to reduce the Form Width below 123 pixels
please. Thanks.

Peter,
 
Can someone tell me how to reduce the Form Width below 123 pixels
please. Thanks.

Try removing the Control Box and setting the Minimum Size (Width) to a
number > 0.
 
Try removing the Control Box and setting the Minimum Size (Width) to a
number > 0.

Jeff

Thanks for the propmpt suggestion. I've set the Form1 properties (in
a new Windows Application project) as follows:
ControlBox = False
MinimizeBox = False
MaximizeBox=False
Text="" (empty string)
MinimumSize = (0,1)

That has solved the problem in the IDE. I can now get a much narrower
form with a width less than 123 pixels by dragging the right border of
the Form.

However, it still doesn't allow me to set a narrow form width using
code. Try this:

Add two radion buttons to the form and the following code. Set the
Text property for each RadioButton to "V" and "H" to make them as
small as possible. Add the following code to the form:

Public Class Form1

Private Sub optVertical_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles optVertical.Click

ClientSize = New Size(10, 373)

End Sub

Private Sub optHorizontal_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles optHorizontal.Click

ClientSize = New Size(479, 81)

End Sub
End Class

When optVertical_Click is executed the width of the form reduced but
not to 10 pixels.

Peter,
 
Peter said:
If you create a new Windows Forms application in Visual Studio 2005
you'll get a project with a single form with FormBorderStyle =
Sizeable. In the designer if you drag the right edge of the form and
try to make the form as narrow as possible the form width will reduce
to 123 pixels (on my system) and then can't be reduced further. What
is controlling this?

IIRC this is the size of the form when minimized outside the taskbar.

You may want to set the form's 'Region' property to a smaller rectangle.
 
IIRC this is the size of the form when minimized outside the taskbar.

You may want to set the form's 'Region' property to a smaller rectangle.

Herfried

Thanks for the Form.Region property tip. I've tried this and it now
seems that I can make the Form as narrow as I wish. However, could
you clarify your "IIRC this is the size of the form when minimized
outside the taskbar." comment.

When the Form is first displayed Form.Region = Nothing. Am I correct
in assuming Form.Region should describe a rectangle that is slighty
larger than Form.Size?

Peter,
 
Peter said:
Thanks for the Form.Region property tip. I've tried this and it now
seems that I can make the Form as narrow as I wish. However, could
you clarify your "IIRC this is the size of the form when minimized
outside the taskbar." comment.

Set the form's 'ShowInTaskBar' property to 'False' and minimize it. It will
minimize to something similar to a button on the desktop which IIRC has the
same size as the minimum size you can set in the designer, etc.
When the Form is first displayed Form.Region = Nothing. Am I correct
in assuming Form.Region should describe a rectangle that is slighty
larger than Form.Size?

The 'Region' property serves a different purpose. It's typically used to
assign a custom shape to the form, which can be a rectangle too. However, I
assumed that your form does not have border and title bar, so it won't work
that seamless if this is not the case.
 
Herfried K. Wagner said:
Set the form's 'ShowInTaskBar' property to 'False' and minimize it. It will
minimize to something similar to a button on the desktop which IIRC has the
same size as the minimum size you can set in the designer, etc.


The 'Region' property serves a different purpose. It's typically used to
assign a custom shape to the form, which can be a rectangle too. However, I
assumed that your form does not have border and title bar, so it won't work
that seamless if this is not the case.
i have had a similar issue in a pplication iam trying to write, after much
hunting around ( far more than i anticipated) i found this information

http://delphi.about.com/od/adptips2006/qt/noform_minwidth.htm

as i am new to C# and the windows environment, i understand nothing of what
is being explained apart from its seems to be what i need. if any one can
convert this to C# i would be very grateful ?

thanks
 
Back
Top