无法从comboBox中选择值后移动下一个表单

时间:2014-08-28 09:48:18

标签: c#

选择组合框值后,我无法移动下一个表单。 我的按钮单击是

namespace Combobox
{
   public partial class Form1 : Form
   {
      private void button1_Click(object sender, EventArgs e)
      {
          if(combo.SelectedItem.ToString()=="Yes Bank")
          {
                Emp newForm = new Emp();
                newForm.Show();
                this.Hide();
          }
          else if (combo.SelectedItem.ToString()=="Bitsforge")
          {
                Temp newForm = new Temp();
                newForm.Show();
                this.Hide();
          }
    }
}

1 个答案:

答案 0 :(得分:1)

请参阅以下代码段。我在这个示例中没有发现任何问题:

using System;
using System.Windows.Forms;

namespace ComboBox
{
public class Temp : Form
{
    public Temp()
    {
        this.Text = "Bitsforge";
    }
}
public class Emp : Form
{
    public Emp()
    {
        this.Text = "Yes Bank";
    }
}
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        if (combo.SelectedItem.ToString() == "Yes Bank")
        {
            Emp newForm = new Emp();
            newForm.Show();
            this.Hide();
        }
        else if (combo.SelectedItem.ToString() == "Bitsforge")
        {
            Temp newForm = new Temp();
            newForm.Show();
            this.Hide();
        }
    }
}

}

您可以从以下网址下载示例应用程序:https://drive.google.com/file/d/0B4OTJAUnKQn4N24za205cWc0cms/edit?usp=sharing