你如何调整窗体来自动适应其内容吗

你如何调整窗体来自动适应其内容吗

本文介绍了你如何调整窗体来自动适应其内容吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现以下行为:

在一个表格有一个TabControl。在那的TabControl有一个TreeView。为了防止出现滚动条,我想根据树形视图中的内容显示,第一次当形式改变其大小。

On a form there is a tabcontrol. On that tabcontrol there is a treeview. To prevent scrollbars appearing, I would like the form to change its size according to the contents of the treeview when displayed for the first time.

如果树形视图已显示在表格的默认大小节点过多,形式应该改变它的大小,以便有在树状没有垂直滚动条(到由屏幕的大小)允许的最大尺寸。

If the treeview has too many nodes to be displayed on the default size of the form, the form should change it's size so that there is no vertical scrollbar on the treeview (up to a maximum size allowed by the size of the screen).

我需要知道的是,如果有可能通过控件的属性来实现此行为。我敢肯定,这可以通过计算来实现,并设置编程元素的大小,但我想知道是否有一种方法由像AutoSizeMode等设置来实现这一点。

What I need to know is, if it is possible to achieve this behaviour through the properties of the controls. I'm sure this can be achieved by calculating and settings the sizes of the elements programmatically, but I would like to know if there is a way to achieve this by settings like AutoSizeMode etc.

[更新]

这是第一个对话框我的应用程序的用户将看到:这是一个对话框来选择数据库一起工作。这是数据库列表,用一个TabControl,buttens等。如果列表太长,滚动条出现,我的一个同事希望他们消失。

It's the first dialog a user of my application sees: It's a dialog to select the database to work with. It's a list of databases, with a tabcontrol, buttens etc. If the list is too long, scrollbars appear and a colleague of mine wants them to disappear.

推荐答案

使用的自动调整大小和AutoSizeMode属性。

Use the AutoSize and AutoSizeMode properties.

一个例子:

private void Form1_Load(object sender, EventArgs e)
{
    // no smaller than design time size
    this.MinimumSize = new System.Drawing.Size(this.Width, this.Height);

    // no larger than screen size
    this.MaximumSize = new System.Drawing.Size((int)System.Windows.SystemParameters.PrimaryScreenWidth, (int)System.Windows.SystemParameters.PrimaryScreenHeight);

    this.AutoSize = true;
    this.AutoSizeMode = AutoSizeMode.GrowAndShrink;

    // rest of your code here...
}

这篇关于你如何调整窗体来自动适应其内容吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 05:56