MinimumSize & MaximumSize don't work with AutoScale forms
From: Aaron Heusser (anonymous_at_discussions.microsoft.com)
Date: 02/05/04
- Next message: SteveV: "Re: expanding dropdownlist control values width dynamically"
- Previous message: Herfried K. Wagner [MVP]: "Re: Programmatically obtain the name of the assembly"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 5 Feb 2004 10:06:07 -0800
I have encountered a problem that I believe is an issue with VS.NET 2003 (or in the .NET framework v1.1).
I have a form that I created in the designer. I wanted this form to be user-sizeable in the horizontal direction only. To accomplish this goal I kept the default AutoScale (i.e., true) so that my form would adjust according to the user's display settings. Additionally, in the form designer I set the following:
- MinimumSize to be equal to the form's default (i.e., current) size
- MaximumSize height to be equal to the form's default height
- MaximumSize width to be "unlimited" (i.e., 99999999)
On some test display configurations, the form doesn't display properly. The form was not as tall as it should be ... thus resulting in controls within the form being vertically clipped.
I searched around to see if anyone else has encountered the same problem and didn't turn up anything definitive. I suspected that the problem might be that the MinimumSize and/or MaximumSize values weren't getting AutoScale adjusted properly. I don't know for certain if this is the case, but I did find a viable workaround: don't set the MinimumSize or MaximumSize values in the designer, but do it in code instead (e.g., in the Layout event):
private bool m_firstLayout = true;
// ...
private void Form_Layout(object sender, System.Windows.Forms.LayoutEventArgs e)
{
// Specifying minimum and maximum sizes in the form designer does not work correctly
// for forms that have AutoScale set to true. Following is a workaround. By the time
// the Layout event is called, the form's size has been adjusted by the AutoScale.
if(m_firstLayout)
{
// minimum size is the same as the default size
MinimumSize = Size;
// maximum size: height is the same as the default size, width is unlimited
Size maximumSize = Size;
maximumSize.Width = 99999999;
MaximumSize = maximumSize;
m_firstLayout = false;
}
}
Following are the specific machine configurations that I observed the problem with (although I suspect the problem is not limited to these configurations).
Development machine (configuration where the form was built):
- Windows 2000 SP4
- Visual Studio .NET 2003
- Form was designed/developed while machine display settings were:
Screen resolution: 1920x1400
Advanced / General / Font size: "Large Fonts"
System font: "Tahoma 8pt"
Test machine (this configuration exhibits the problem):
- Windows XP Professional SP1
- Display settings:
Screen resolution: 1600x1200
Advanced / General / DPI setting: "Large size (120 DPI)"
Appearance / Font size: "Normal"
- Next message: SteveV: "Re: expanding dropdownlist control values width dynamically"
- Previous message: Herfried K. Wagner [MVP]: "Re: Programmatically obtain the name of the assembly"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|