Managing mulch window forms in C # application

Any thoughts, recommendations, patterns on a good way to manage your multiple form application.

The first page is the login that loads the "main form", from there the user can launch a number of other "subforms" (may grow over time). The user should be able to cancel the entire application at any time.

I know how I do it now, it is not always elegant.

Cody

+2


source to share


7 replies


Consider using the DockPanel Suite . It allows you to create multiple forms and have a complete panel docking solution for your application.



+3


source


I like the Explorer-style interface: use a separator on the main form. Use a list or tree control on the left and add a link to each subform as a tag for the item. When the user clicks on the element, click the sub-shape from the tag to the right side of the divider.



You can monitor the selected change event in the list / tree to perform a level check on the level.

+2


source


There is nothing fundamentally wrong with how you set it up, but I would change the relationship between your login form and the main form so that your main form is not loaded by your login form.

In the main method in your Program.cs file replace this (suggested) line:

Application.Run(new LoginForm());

      

with something like this:

LoginForm login = new LoginForm();
DialogResult result = login.ShowDialog();
login.Dispose();
if (result != DialogResult.Cancel)
{
    Application.Run(new MainForm());
}

      

Rewrite your LoginForm to simply return DialogResult.OK

if login succeeds ( this.DialogResult = DialogResult.OK

), instead of loading and displaying the MainForm instance.

From now on, there is nothing wrong with loading and displaying additional forms from MainForm, provided such an interface makes sense for your program (for example, a graphics editing program that includes various other floating tool windows as needed).

The user can "undo" your entire application by simply closing the main form, which is quite normal for a Windows program.

+2


source


"for managing an application with multiple forms.

Hi Cody,

Council. Keep in mind that you have access to a very convenient way to find out, at all times (in any context where you use the System.Windows.Forms library), the number of open forms in an application via:

Application.OpenForms.Count

      

I think a lot depends on what you mean by "manipulating" your plural forms and what you mean by the term "subforms". I assume that you are already familiar with the built-in MDI in .NET and are looking for an alternative to this, or you will not be asking this question. Please correct me if my assumptions are wrong.

If you mean by "subforms": forms created within your "Main Form" then they will of course be removed when the main form is closed.

I personally like the multiple independent windows model in WinForms, sometimes called SDI + (I think Chris Sells came up with this acronym).

I like to start by "hi-jacking" the standard Program.cs file, so the basic procedure looks like this:

    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Initializer.Initialize();
        // it now your responsibility to shut down the application !
        Application.Run();
    }

      

Where "Intializer is a public static class with one public static method" Intialize; it might look something like this:

 public static class Initializer
 {
    public static StartFormTemplate StartForm;

    public static MainFormTemplate MainForm;

    public static void Initialize()
    {
        MainForm = new MainFormTemplate();
        MainForm.FormClosing += new FormClosingEventHandler(FormClosing);
        // StartForm will display MainForm in this case
        // MainForm.Show();

        StartForm = new StartFormTemplate();
        StartForm.FormClosing += new FormClosingEventHandler(FormClosing);
        StartForm.Show(); 
    }
  }

      

Each form created within the Initializer class will be an "independent window" (effectively with: Parent == null).

The interesting "business" in this model is the logic in the FormClosing event (not shown here), which in this example separates both StartForm and MainForm. You can easily check the closing of the Mainform by taking the "sender" parameter of the FormClosing call and comparing it to the MainForm:

MainForm == sender

      

And you can use Application.OpenForms.Count to detect when there is only one "independent" window left. The tricky part is making sure you detect cases where you want MainWindow to open and handle them first, canceling the FormClose event as needed.

I think this is enough for starters: it might be the "primrose path" that you really don't want to downgrade :)

best, bill

+1


source


I would recommend Application Application UI Smart Client.

The block is designed to help you create complex WinForm based solutions. It provides a proven architecture and implementation that helps you build applications using common patterns found in linear business applications.

  • This allows your application to be based on the concept of modules or plugins.
  • Maintainable, reusable code through UI composition.
  • This facilitates development by using templates for loose communication between modules.
  • Separating the model (business logic and data access) from the presentation.
  • Figure Model-View-Presenter.
+1


source


You can use MDI . To do this, set the IsMdiContainer property of the parent to true and set the MdiParent property of each child to the parent before the child is shown. Then you can use the MdiList menu to automatically display all child forms.

Alternatively, you can use tabs; this is easiest to do with a third party framework.

Finally, you could do this normally by calling the Show method on each child form with the parent form as a parameter.

For a more detailed and specific answer, please provide more detailed information.

0


source


I am using a navigation style UI for this kind of thing. Check out this article on MSDN which describes a WinForms framework for inductive applications.

0


source







All Articles