C# switch between forms inside a form like in MSN

89 Views Asked by At

I remember MSN Messenger used to display a login. And upon logging in, it displayed a loading animation. On success it displayed all your contacts. All that in one single form.

How is that done?

I dont only know how to make new forms, or display forms inside forms. But that is not how its done, right?


I am opened to suggestions on how to improve my question. I know I barely could explain myself. Perhaps with your help, i can edit my question to be more helpful to others

1

There are 1 best solutions below

4
martijn On BEST ANSWER

you can user the UserControl object. You can dock them to a panel in the main form.

This example uses a Panel object in the main form for docking (named pnlCentre).

public partial class MainForm : Form
{
    DummyControl1 dummy1;
    DummyControl2 dummy2;

    public MainForm()
    {
        InitializeComponent();


        dummy1 = new DummyControl1();
        dummy2 = new DummyControl2();

        pnlCentre.Controls.Add(dummy1);
        pnlCentre.Dock = DockStyle.Fill;
    }
    // switches between screens
    public void switchscreen()
    {
        pnlCentre.Controls.Remove(dummy1);
        pnlCentre.Controls.Add(dummy2);
        pnlCentre.Dock = DockStyle.Fill;

    }

}

public partial class DummyControl1 : UserControl
{
    // can be filled from the designer
}

public partial class DummyControl2 : UserControl
{
    // can be filled from the designer
}