public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
System.Windows.Forms.ComboBox comboBox = new System.Windows.Forms.ComboBox();
System.Windows.Forms.ComboBox comboBox2 = new System.Windows.Forms.ComboBox();
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBox1.Text)
{
case "1":
label1.Text = "1.压力";
label2.Text = "2.流量";
label3.Text = "";
comboBox.Visible = false;
cmb_ll.Visible = true;
cmb_yl.Visible = true;
comboBox2.Visible = false;
// cmb_yl.Text = "压力";
// cmb_ll.Text ="流量";
cmb_yl.Items.Clear();
cmb_ll.Items.Clear();
cmb_yl.Items.Add("300pa");
cmb_yl.Items.Add("200pa");
cmb_yl.Items.Add("100pa");
cmb_yl.SelectedIndex = 0;
cmb_ll.Items.Add("30m³/h");
cmb_ll.Items.Add("40m³/h");
cmb_ll.Items.Add("50m³/h");
cmb_ll.SelectedIndex = 0;
break;
case "2":
label1.Text = "1.天气";
label2.Text = "2.地理";
// 设置新Label的位置,使其在existingLabel下方并距离existingLabel 10像素
label3.Location = new Point(label2.Location.X, label2.Location.Y + label2.Height + 20);
cmb_ll.Visible = true;
cmb_yl.Visible = true;
// label3.Controls.Add(label3);
label3.Text = "3.物理";
comboBox.Visible = true;
comboBox.Location = new Point(cmb_ll.Left, cmb_ll.Bottom + 15); // 设置ComboBox2的位置
comboBox.Width = comboBox1.Width; // 设置与ComboBox1相同的宽度
comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
// 添加项到ComboBox
comboBox.Items.Add("100分");
comboBox.Items.Add("200分");
comboBox.Items.Add("300分");
// 可以设置默认选中的项
comboBox.SelectedIndex = 0;
this.Controls.Add(comboBox);
cmb_yl.Items.Clear();
cmb_ll.Items.Clear();
cmb_yl.Items.Add("7");
cmb_yl.Items.Add("8");
cmb_yl.Items.Add("9");
cmb_yl.SelectedIndex = 0;
cmb_ll.Items.Add("7");
cmb_ll.Items.Add("8");
cmb_ll.Items.Add("9");
cmb_ll.SelectedIndex = 1;
break;
case "3":
// label1.Text = "1.数学";
// label2.Text = "英语 ";
label1.Text = " ";
label2.Text = " ";
// 设置新Label的位置,使其在existingLabel下方并距离existingLabel 10像素
label3.Location = new Point(label2.Location.X, label2.Location.Y + label2.Height + 20);
// label3.Controls.Add(label3);
label3.Text = "化学 ";
cmb_ll.Visible = false;
cmb_yl.Visible = false;
comboBox2.Visible = true;
comboBox2.Location = new Point(cmb_ll.Left, cmb_ll.Bottom + 15); // 设置ComboBox2的位置
comboBox2.Width = comboBox1.Width; // 设置与ComboBox1相同的宽度
comboBox2.DropDownStyle = ComboBoxStyle.DropDownList;
//comboBox.Items.Clear();
// 添加项到ComboBox
comboBox2.Items.Add("400分");
comboBox2.Items.Add("500分");
comboBox2.Items.Add("600分");
// 可以设置默认选中的项
comboBox2.SelectedIndex = 0;
this.Controls.Add(comboBox2);
cmb_yl.Items.Clear();
cmb_ll.Items.Clear();
cmb_yl.Items.Add("7");
cmb_yl.Items.Add("8");
cmb_yl.Items.Add("9");
cmb_yl.SelectedIndex = 0;
cmb_ll.Items.Add("7");
cmb_ll.Items.Add("8");
cmb_ll.Items.Add("9");
cmb_ll.SelectedIndex = 1;
break;
}