简体   繁体   English

如何使控件占据父母身高的80%

[英]How can I make a control take 80% of the parent's height

I know you can dock an item to cover the bottom, top, left, right, or all of the form. 我知道您可以停靠一个项目以覆盖底部,顶部,左侧,右侧或所有表单。 But I want to have a datagridview cover 80% of the height of the forum and all of the width and cannot figure out how to do that. 但是我想让datagridview覆盖论坛高度的80%和所有宽度,并且无法弄清楚该怎么做。

You can use the TableLayoutPanel ( MSDN ) to accomplish this, and can be done entirely in the designer. 您可以使用TableLayoutPanelMSDN )完成此操作,并且可以完全在设计器中完成。

Add a TableLayoutPanel and have it fill you entire form. 添加一个TableLayoutPanel并使其填满整个表单。 Then, create 2 rows in the panel and give the first row a percentage value of 80% for height (Your options are percentage, pixels, and auto-fill). 然后,在面板中创建2行,并为第一行的高度百分比设置为80%(您的选项是百分比,像素和自动填充)。 Finally, move your DataGridView into the first row and dock it to the entire row. 最后,将DataGridView移到第一行并将其停靠到整行。

You can use the docking (eg Top or Bottom ) to setup the width part of your problem, however, to synchronize the height you'll need to programmatically calculate it (and keep it synced). 您可以使用对接(例如TopBottom )来设置问题的宽度部分,但是,为了同步高度,您需要以编程方式计算它(并使其保持同步)。

There's an example here that sets the width so that idea will apply: https://stackoverflow.com/a/18384344/33969 . 这里有一个设置宽度的示例,这样想法就可以应用: https : //stackoverflow.com/a/18384344/33969 You'll want to call that function on form load, but also as an event handler for the Form.Resize event . 您将要在表单加载时调用该函数,还要将其作为Form.Resize event的事件处理程序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使ListView的项目占据所有可用高度? - How can i make a ListView's items take up all the available height? 如何创建具有父控件默认字体的用户控件? - How can I create a User Control with the default font of it's parent? 如何通过子控件事件更改父控件的内容? - How can I change parent control's content though child control event? 如何从子控件的resize事件调整父控件的大小? - How can I resize the parent control from a child control's resize event? 为了鼠标事件,如何将Popup包含在其父控件中? - How do I make a Popup included in it's parent Control for the sake of mouse events? 如何确保控件在滚动控件内部时可见? - How can I make sure a control is visible when it's inside a scrolling control? 如何阻止父控件的重绘在其子控件的重绘之前排成一行? - How can I stop a parent control's repaints from jumping in line, in front of its child controls' repaints? 如何制作一个可预滚动的标签控件,以便我可以添加大量文本框而无需占用整个屏幕的窗体 - how to make a prescrollable tab control so i can add in tons of text boxes without having the form not take up the entire screen 如何在C#中拍摄Winforms控件/窗体的屏幕截图? - How can I take a screenshot of a Winforms control/form in C#? 如何在滚动的TreeView中使控件跟随其父级? - How do I make a Control follow its parent in a scrolling TreeView?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM