现在Winform程序有个要求,Form1分钟未操作则返回MainForm
请问这该怎么做呢? 能给代码看一下吗

解决方案 »

  1.   

    建立一个Timer控件,Enable属性设为true,刷新时间设为1000(即1秒)
    在Timer控件外建立一个变量例如(public static) int num = 0;然后双击建立的Timer控件,在里面写如下代码:num = num + 1;
    if(num == 10)
    {
    关闭代码。
    }然后在你的每一次操作的代码中,添加num = 0进行计时的更新。
      

  2.   

    用timer  里边有个事件 ,然后在事件里写方法 ,事件会定时触发的 。时间可以设定。
      

  3.   

    定时器 我知道 
    Winfrom程序中有很多Form阿 
    比如MainForm-->Form1-->Form2
    要从Form2返回到MainForm 怎么搞阿
      

  4.   

    方法不很,定时器比较简单了,上面说了
    System.Timers.Timer timer = new System.Timers.Timer();
    timer有自己的循环事件,这个和while差不多,只是不需要多线程处理,好处理
    循环和下面的while中代码差不多或者用while
    bool IsOp = false;//未操作检测,全局关键字
    int count = 0;
    进入form启动循环
    while(true)
    {
       if(IsOp == true)
         {
             count = 0;
             IsOp = false;
         }
       else
         count ++;
       if(count >= 60)
        {
           //返回mian
        }
       Thread.Sleep(1000);//暂停一秒
    }这个方法注意要用多线程运行,IsOp的修改也要加锁,避免崩溃
      

  5.   

    override on close()
    {
        this.parant.close();
        basc.close();
    }//定义好这个parant
      

  6.   

    我就是问 
    //返回Main
    这里的代码该怎么写阿
      

  7.   

    你试试这一句话
                foreach (Form myForm in Application.OpenForms)// 遍历所有子窗
                    MessageBox.Show(myForm.Text);
    写到定时器里,如果不是主窗口,就关闭。
    我没试,你试一下,看行不行
      

  8.   

    MainForm-->Form1-->Form2
    Form2计数器超时,则把Form2关闭,再把Form1关闭就返回到了MainForm中Form2计数器超时        #region 页面计数器
            /// <summary>
            /// 计数器
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void timer_Tick(object sender, EventArgs e)
            {
                timerCount++;
                if (timerCount > Constants.timerMaxCount)
                {
                    this.timer.Stop();
                    this.bCloseSystem = true;
                    this.Dispose();
                    this.Close();
                }
            }
            #endregion关闭Form1                this.timer.Stop();
                    Form2 form2 = new Form2(pdfStr);
                    form2.ShowDialog();
                    if (form2.bCloseSystem)
                    {
                        this.Dispose();
                        this.Close();
                    }
                    else
                    {
                        this.timer.Start();
                    }