I have built quite big WinForms application working in industry for a few years. It communicates with many HW devices. Application can be configured to use or not use some of these devices and GUI is modified by this configuration. Now, even more devices (and application possible configurations) are going to be added, so I need to refactor whole application, maybe even write the most of it again and it will be very painful work as it was generally my the first bigger project.
I'm especially afraid of making GUI dependent on application configuration. At this moment, I have many controls in my Form.Designer.cs
file (created in drag&drop designer), and I'm enabling/disabling some buttons, changing text of some labels, adding or removing panels etc in ArrangeControls()
function according to configuration, also in Form.Designer.cs
file.
This function is something like this:
void ArrangeControls(Config hwCfg)
{
if (!hwCfg.dev1&& !hwCfg.dev2&& !hwCfg.dev3&& !hwCfg.dev4)
{
panelDevices.Dispose();
lastPannel = panelTime;
}
else
{
if(hwCfg.dev1)
...
else
...
}
...
}
This is very disgusting solution with few hundreds of lines at this moment and I even need to add more controls and more possible combinations of controls appearance. Can you suggest me some pattern, how to get this problem under control?