C# 当窗口最大化时,如何使控件自行调整大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1603526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 19:17:33  来源:igfitidea点击:

How can I make a control resize itself when the window is maximized?

c#.netwinforms

提问by ryeguy

I can't seem to figure this out. I have two group boxes on the left side of my form window. When the window is normal size (1000x700), the two boxes are the same. However, when the window is maximized, it ends up looking like this: http://imgur.com/X2Ou7.png

我似乎无法弄清楚这一点。我的表单窗口左侧有两个组框。当窗口为正常大小(1000x700)时,两个框是一样的。但是,当窗口最大化时,它最终看起来像这样: http://imgur.com/X2Ou7.png

What I want is for both the "Log" group box and the tab control to extend down to the bottom of the window. I have tried messing with anchoring, but that just seems to move it and not resize it. Docking fills the whole side. What options do I have here?

我想要的是“日志”组框和选项卡控件都向下延伸到窗口底部。我试过搞乱锚定,但这似乎只是移动它而不是调整它的大小。对接填满整个侧面。我在这里有哪些选择?

采纳答案by Jacob Seleznev

Make Log's

制作日志

Anchor property= Top|Left|Bottom.

Anchor property= Top|Left|Bottom.

Make tab control's

制作选项卡控件

Anchor property = Top|Left|Bottom|Right

Anchor property = Top|Left|Bottom|Right

回答by Jason Williams

If you anchor to the top, it'll move the whole control up and down. If you anchor to top+bottom, it'll stretch the control so that it grows as the form grows.

如果您锚定到顶部,它将上下移动整个控件。如果您锚定到顶部+底部,它会拉伸控件,使其随着表单的增长而增长。

回答by DeepakJoseLopez

You could change the Maxproperty along with the other event changed. Check this:

您可以在更改Max其他事件的同时更改该属性。检查这个:

private void frm_Resize(object sender, EventArgs e)
{
   if (this.ParentForm.WindowState == FormWindowState.Normal && 
       this.WindowState == FormWindowState.Maximized)
   {
      this.ParentForm.WindowState = FormWindowState.Maximized;
   }
}