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

本秂侑毒 提交于 2020-01-14 12:58:07

问题


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.


回答1:


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.

Edit: The source code is from NBug project.



来源:https://stackoverflow.com/questions/5679086/how-do-i-create-dynamic-panel-to-be-shown-and-hide-using-difference-choices-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!