Search code examples
c#maintainability

C# Multi-form coding practice


My question is, in general is it allowable and maintainable to have a multi-form program. More specifically in C# is it good practice to have a button go to another form(each button would be in a separate class). Here is an example: (In this example I create a programmers reference application, where I need to go from page to page gathering information from the web and put it on an application for quick reference)

Main form:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProgramersReference
{
public partial class main : Form
{
    public main()
    {
        InitializeComponent();
    }

    //About button click
    private void btnAbout_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Author: anon \n"
            +"Version Number: 00.00.01 \n"
            ,"Information");    //Version Key quickreference: 00(high profile change).00(Medium profile change).00(low profile change)
    }

    private void btnWebsites_Click(object sender, EventArgs e)
    {
        websiteForm websiteFormObj = new websiteForm();
        websiteFormObj.Show();
    }
 }
}

Second form(IN A DIFFERENT CLASS):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProgramersReference
{
  public partial class websiteForm : Form
   {
    public websiteForm()
    {
        InitializeComponent();
    }
   }
}

If this is not a good way can you answer what is a better way, is tab control a better way, or using panels to show and hide new content in an application?


Solution

  • Look at the big programs. Is steam using new windows for each action. Is Visual Studio using alot of new windows for every single action. The are all using tabs for the diffrent pages. It will get very messy if the do.

    The reason why Pop up windows are created is to get some input from the user. For example:

    1. Saving a file
    2. Opening a file
    3. Creating a new class in Visual studio.
    4. Change Settings.

    All these popup windows are created when a program want to have some input without disturbing the main layout and the program goal. These windows will also close quickly.

    So only create popup windows when they will quickly disapear after the user gave some input. And put the main functions of your program in tabs.