如何提高Windows窗体设计器在大窗体中的性能?

发布于 2025-01-13 08:06:22 字数 274 浏览 3 评论 0原文

在我工作的地方,我发现一个具有大表单的应用程序,其中有一个选项卡控件和 14 个选项卡页,每个选项卡页都有很多彼此重叠的控件和面板,这使得 Windows 窗体设计器非常慢。保存需要 1 分钟,更改选项卡页面和更改文本框属性需要 10 秒以上。

我尝试以较小的形式分离选项卡页,并将这些形式称为选项卡页的子级,以创建选项卡页处于同一形式的错觉,但这不起作用,因为当我将表单加载到选项卡页中时,所有尺寸而且位置都乱了。

有没有一种方法可以提高 Windows 窗体设计器的性能而不彻底改变应用程序的工作方式?

Where i'm working i have found an application with a big form that has a tabcontrol and 14 tabpages, every tabpage has a lot of controls and panels that overlap each other, this makes windows form designer really slow. It takes 1 minute to save and over 10 seconds to change a tabpage and change a textbox property.

I tried to separate the tabpages in smaller forms and call the forms as children of a tabpage to create the illusion of the tabpages being in the same form, but that didn't work, because when i load the form into a tabpage then all sizes and locations are messed up.

There is a way to improve the performance of the windows form designer without changing drastically the way the application works?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱本泡沫多脆弱 2025-01-20 08:06:22

创建 14 个 UserControls 并调整选项卡控件的大小以仅显示选项卡header 并在选项卡控件下方放置一个 Panel 作为占位符。然后,当选择选项卡页时,动态地将用户控件之一添加到面板,并将停靠设置为 Fill

public Form1()
{
    InitializeComponent();
    SelectUserControl();
}

private void TabControl1_Selected(object sender, TabControlEventArgs e)
{
    SelectUserControl();
}

private void SelectUserControl()
{
    UserControl? uc = (tabControl1.SelectedIndex + 1) switch {
        1 => new UserControl1(),
        2 => new UserControl2(),
        3 => new UserControl3(),
        ...
        14 => new UserControl14(),
        _ => null
    };
    if (uc is not null) {
        while (panel1.Controls.Count > 0) {
            panel1.Controls[0].Dispose();
        }
        uc.Dock = DockStyle.Fill;
        panel1.Controls.Add(uc);
    }
}

当然,您需要添加代码来在用户控件更改时加载和保存值或设置数据绑定 来源。

但如果你说保存需要1分钟,那么你的保存过程可能不是最优的。

Create 14 UserControls and resize the tab control to only show the tabs header and place a Panel as placeholder below the tab control. Then when a tab page is selected dynamically add one of the user controls to the panel with docking set to Fill.

public Form1()
{
    InitializeComponent();
    SelectUserControl();
}

private void TabControl1_Selected(object sender, TabControlEventArgs e)
{
    SelectUserControl();
}

private void SelectUserControl()
{
    UserControl? uc = (tabControl1.SelectedIndex + 1) switch {
        1 => new UserControl1(),
        2 => new UserControl2(),
        3 => new UserControl3(),
        ...
        14 => new UserControl14(),
        _ => null
    };
    if (uc is not null) {
        while (panel1.Controls.Count > 0) {
            panel1.Controls[0].Dispose();
        }
        uc.Dock = DockStyle.Fill;
        panel1.Controls.Add(uc);
    }
}

Of course you will have add code to load and save values when the user control changes or to set the Data Binding source.

But if you say that it takes 1 minute to save, then maybe your saving procedure is suboptimal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文