1

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?

Alaa
  • 115
  • 12
  • I think it is a personal opinion about the style layout. It realy depents on what program you are trying to create. What you can try is dockable windows like VisualStudio : http://dockpanelsuite.com/. – Timon Post Apr 01 '17 at 21:08
  • @TimonPost But in terms of maintainability in the future would it be good practice for every button to be in a different class, and that same button be mapped to another form? Thank you for the comment. – Alaa Apr 01 '17 at 21:11
  • I tried to use panels with usercontrol long time ago. Note that you should pay attention to event handlers. Otherwise will drain memory. For me is much cleaner with tabbed docs, but for a clean code try to make a different class for each tab. – Adrian Stanculescu Apr 01 '17 at 21:11
  • Try to read before about MVP pattern. From posted code you're using winforms. – Adrian Stanculescu Apr 01 '17 at 21:13
  • @AdrianStanculescu Thank you for the response. – Alaa Apr 01 '17 at 21:13

2 Answers2

2

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.

Timon Post
  • 2,779
  • 1
  • 17
  • 32
2

I agree with what Timon said in general, but it always depends on what you are trying to achieve. Programming is a creative process and rules should be viewed as guidelines. If your application works better with tabs use tabs if it works better with forms use forms. If your writing this application for a client discuss the issue with them. As to best practice, I don't see an issue with either option.

Hope me ramblings help Danny

dannyhut
  • 179
  • 11