Search code examples
c#user-interfacecomboboxpanelnbug

How do I create dynamic panel to be shown and hide using difference choices in combo box in C#?


I want to make a GUI which is dynamic, meaning that the GUI will change depending on the choice which user makes on the combo box.

For example, if combo box consists of {English, Spanish, French}, the panel on the bottom of the combo box will change its description language depending on the choice.

To do this, I believe I have to do something like clear panel then redraw panel, but I have no idea how.

Can someone tell me how to make this happen in details on Visual Studio 2005 C#?

Thank you in advance.


Solution

  • I have this exact implementation right here: http://nbug.codeplex.com/SourceControl/changeset/view/6081#107027 which implements an IPanelLoader (ISubmitPanel for my case) interface and loads any panel with the same name of that in a combo box. Basically download the source code and compile it and have a look at the "Configurator" project. There are a lot of things which would take me pages to explain but there is already a full blown example.

    In my case, any form implementing the ISubmitPanel interface (MailForm, FtpForm etc. in my case) can be loaded like this:

    private void SubmitComboBox_SelectedIndexChanged(object sender, EventArgs e)
    {
        switch (this.submitComboBox.SelectedItem.ToString())
        {
            case "E-Mail":
                this.Controls.Add(new MailForm());
                break;
            case "FTP":
                this.Controls.Add(new FtpForm());
                break;
            case "HTTP":
                this.Controls.Add(new HttpForm());
                break;
        }
    }
    

    Ofcourse this code should run in another form where you want to load the other form into.

    Dropdown to load panels

    E-Mail panel loaded

    Edit: The source code is from NBug project.