使用组合框选择时C#:if语句错误

时间:2017-12-15 02:11:08

标签: c#

选择' Jewelry'来自组合框的" txt_qty& label6"正在观看哪种形式,但在选择Gem时," textBox5& label18"它没有观看。请帮忙

 private void combo_main_type_SelectedIndexChanged(object sender, EventArgs e)
    {

        if ((string)combo_main_type.SelectedItem == "Jewelry")
        {
            txt_qty.Visible = true;
            label6.Visible = true;
            txt_qty.Location = new System.Drawing.Point(213, 343);
            label6.Location = new System.Drawing.Point(40, 348);
        }
        else if ((string)combo_main_type.SelectedItem == "")
        {
            txt_qty.Visible = false;
            label6.Visible = false;

        }
        else if ((string)combo_main_type.SelectedItem == "Gem")
        {
            textBox5.Visible = true;
            label18.Visible = true;
            textBox5.Location = new System.Drawing.Point(213, 343);
            label18.Location = new System.Drawing.Point(40, 348);
        }
        else
        {
            textBox5.Visible = false;
            label18.Visible = false;
        }


    }

1 个答案:

答案 0 :(得分:0)

您需要做的是遵循。

private void combo_main_type_SelectedIndexChanged(object sender, EventArgs e)
{

    if ((string)combo_main_type.SelectedItem == "Jewelry")
    {
        txt_qty.Visible = true;
        label6.Visible = true;
        txt_qty.Location = new System.Drawing.Point(213, 343);
        label6.Location = new System.Drawing.Point(40, 348);
        textBox5.Visible = false;
        label18.Visible = false;
    }
    else if ((string)combo_main_type.SelectedItem == "Gem")
    {
        textBox5.Visible = true;
        label18.Visible = true;
        textBox5.Location = new System.Drawing.Point(213, 343);
        label18.Location = new System.Drawing.Point(40, 348);
        txt_qty.Visible = false;
        label6.Visible = false;
    }
    else
    {
        textBox5.Visible = false;
        label18.Visible = false;

        txt_qty.Visible = false;
        label6.Visible = false;
    }

}