本文整理汇总了C#中Control.GetAutoSizeMode方法的典型用法代码示例。如果您正苦于以下问题:C# Control.GetAutoSizeMode方法的具体用法?C# Control.GetAutoSizeMode怎么用?C# Control.GetAutoSizeMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Control
的用法示例。
在下文中一共展示了Control.GetAutoSizeMode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LayoutAutoSizeContainer
void LayoutAutoSizeContainer (Control container)
{
int left;
int top;
int width;
int height;
if (!container.VisibleInternal || container.ControlLayoutType == Control.LayoutType.Dock || !container.AutoSize)
return;
left = container.Left;
top = container.Top;
Size preferredsize = container.PreferredSize;
if (container.GetAutoSizeMode () == AutoSizeMode.GrowAndShrink) {
width = preferredsize.Width;
height = preferredsize.Height;
} else {
width = container.ExplicitBounds.Width;
height = container.ExplicitBounds.Height;
if (preferredsize.Width > width)
width = preferredsize.Width;
if (preferredsize.Height > height)
height = preferredsize.Height;
}
// Sanity
if (width < container.MinimumSize.Width)
width = container.MinimumSize.Width;
if (height < container.MinimumSize.Height)
height = container.MinimumSize.Height;
if (container.MaximumSize.Width != 0 && width > container.MaximumSize.Width)
width = container.MaximumSize.Width;
if (container.MaximumSize.Height != 0 && height > container.MaximumSize.Height)
height = container.MaximumSize.Height;
container.SetBoundsInternal (left, top, width, height, BoundsSpecified.None);
}
示例2: GetPreferredControlSize
private Size GetPreferredControlSize (Control child)
{
int width;
int height;
Size preferredsize = child.PreferredSize;
if (child.GetAutoSizeMode () == AutoSizeMode.GrowAndShrink || (child.Dock != DockStyle.None && !(child is Button) && !(child is FlowLayoutPanel))) {
width = preferredsize.Width;
height = preferredsize.Height;
} else {
width = child.ExplicitBounds.Width;
height = child.ExplicitBounds.Height;
if (preferredsize.Width > width)
width = preferredsize.Width;
if (preferredsize.Height > height)
height = preferredsize.Height;
}
if (child.AutoSize && child is FlowLayoutPanel && child.Dock != DockStyle.None) {
switch (child.Dock) {
case DockStyle.Left:
case DockStyle.Right:
if (preferredsize.Width < child.ExplicitBounds.Width && preferredsize.Height < child.Parent.PaddingClientRectangle.Height)
width = preferredsize.Width;
break;
case DockStyle.Top:
case DockStyle.Bottom:
if (preferredsize.Height < child.ExplicitBounds.Height && preferredsize.Width < child.Parent.PaddingClientRectangle.Width)
height = preferredsize.Height;
break;
}
}
// Sanity
if (width < child.MinimumSize.Width)
width = child.MinimumSize.Width;
if (height < child.MinimumSize.Height)
height = child.MinimumSize.Height;
if (child.MaximumSize.Width != 0 && width > child.MaximumSize.Width)
width = child.MaximumSize.Width;
if (child.MaximumSize.Height != 0 && height > child.MaximumSize.Height)
height = child.MaximumSize.Height;
return new Size (width, height);
}
示例3: GetPreferredControlSize
private Size GetPreferredControlSize (Control child)
{
int width;
int height;
Size preferredsize = child.PreferredSize;
if (child.GetAutoSizeMode () == AutoSizeMode.GrowAndShrink || (child.Dock != DockStyle.None && !(child is Button))) {
width = preferredsize.Width;
height = preferredsize.Height;
} else {
width = child.ExplicitBounds.Width;
height = child.ExplicitBounds.Height;
if (preferredsize.Width > width)
width = preferredsize.Width;
if (preferredsize.Height > height)
height = preferredsize.Height;
}
// Sanity
if (width < child.MinimumSize.Width)
width = child.MinimumSize.Width;
if (height < child.MinimumSize.Height)
height = child.MinimumSize.Height;
if (child.MaximumSize.Width != 0 && width > child.MaximumSize.Width)
width = child.MaximumSize.Width;
if (child.MaximumSize.Height != 0 && height > child.MaximumSize.Height)
height = child.MaximumSize.Height;
return new Size (width, height);
}