我这样在time_tick下这么写:
if (comm.IsOpen&&qitaselect.Substring(1, 1) == "1")////////////////////////////////////////////////需修改
            {
                Form12 form12 = new Form12();
form12.show();
                    if (zhuangtai2.Substring(6, 1) == "1")
                    {
                    }
                    else if (zhuangtai2.Substring(6, 1) == "0")
                    {
                        qitaselect = qitaselect.Substring(0, 1) + "0";
                        form12.Visible = false;
                        form12.Close();
                    }
}我利用中断模式调试,发现当zhuangtai2.Substring(6, 1) == "0"时:其下面的三句话: qitaselect = qitaselect.Substring(0, 1) + "0";
                        form12.Visible = false;
                        form12.Close();
都是执行了的,执行完后因总条件“qitaselect.Substring(1, 1) == "1"”不在符合就不会再来执行这段代码了;但是问题是:这样执行后(确认form12.Visible = false;form12.Close();)都是被执行过的,但窗口就是关不掉!!!!!form12.show()能打开窗口,但close()就是关不掉!!!!!!请问这是为什么
?????????????

解决方案 »

  1.   

    如果你想强行退出, this.Close();
    Process.GetCurrentProcess().Kill();
      

  2.   

    我现在吧时钟都停下了,确保他不会创建新的,但还是关不掉!!!这样改,关掉时钟:
    在time_tick下这么写:
    if (comm.IsOpen&&qitaselect.Substring(1, 1) == "1")////////////////////////////////////////////////需修改
      {
      Form12 form12 = new Form12();
    form12.show();
      if (zhuangtai2.Substring(6, 1) == "1")
      {
      }
      else if (zhuangtai2.Substring(6, 1) == "0")
      {
    time1.stop(); 
     qitaselect = qitaselect.Substring(0, 1) + "0";
      form12.Visible = false;
      form12.Close();
      }
    }关掉了时钟,还是关不掉哪个窗口!这是为什么?
      

  3.   

    把timer1.Stop()改为timer1.Enabled = false;试试