0
votes

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?

1

1 Answers

0
votes

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.