为方便起见,在comboBox上方添加一个面板。
并双击您的comboBox,它将生成comboBox_SelectedIndexChanged编写此代码
private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
MyPanel.Controls.Clear();
string selectedText = comboBox.SelectedItem.ToString().ToLower();
if (selectedText == "combobox")
{
MyPanel.Controls.Add(new ComboBox());
}
else if (selectedText == "textbox")
{
MyPanel.Controls.Add(new TextBox());
}
else if (selectedText == "radio")
{
MyPanel.Controls.Add(new RadioButton());
}
else if (selectedText == "checkbox")
{
MyPanel.Controls.Add(new CheckBox());
}
MyPanel.Refresh();
}