PKK
PKK

Reputation: 127

Windows form design advice

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

Answers (2)

Joel Coehoorn
Joel Coehoorn

Reputation: 415630

A few things I noticed:

  1. 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.
  2. 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);.
  3. Inheriting a base form is good. To make it work even better, also build each form as a custom control, such that the only difference among your forms is which custom control you've added. You can also use an interface or common base control for each of these custom controls for further control and enforce a uniform look and feel in your app.

Upvotes: 2

Mitchel Sellers
Mitchel Sellers

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

Related Questions