Reputation: 127
I have built a touch screen application using Windows Forms. It works great but I still would like to have some design advice.
My application consists of several different windows forms.
My design is that I have one MainForm which all of the other forms inherit from. In this Mainform I have the buttons where the user can choose which form to open. When the user chooses one of the options another form is opened. I use the following code:
Control control = this; // the current form, that is open
Recording rec = Recording.Instance; // the form that the user choose to open
if (control != rec) {
rec.Show(); // show the recording form
control.Hide(); // hide the previous form
}
Is this a correct way to work with forms or should I use some other way? For example, have one form and user controls in it.
Upvotes: 2
Views: 548
Reputation: 415630
A few things I noticed:
Recording.Instance
. That looks to me like you are making these forms singleton. That can work, but I'd rather see them created/closed as needed.rec.Show();
This is a nitpick, but a lot of the time you want to pass the current form as an owner: rec.Show(this);
or rec.Show(control);
.Upvotes: 2
Reputation: 63126
This method works, but depending on your application you could have some issues with this long term.
The main area of potential concern is that doing "control.Hide();" keeps the instance of the control in memory, as long as you are ok with this behavior, you are fine.
Upvotes: 1