如何让Winform程序 返回主页面MainForm 现在Winform程序有个要求,Form1分钟未操作则返回MainForm请问这该怎么做呢? 能给代码看一下吗 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 建立一个Timer控件,Enable属性设为true,刷新时间设为1000(即1秒)在Timer控件外建立一个变量例如(public static) int num = 0;然后双击建立的Timer控件,在里面写如下代码:num = num + 1;if(num == 10){关闭代码。}然后在你的每一次操作的代码中,添加num = 0进行计时的更新。 用timer 里边有个事件 ,然后在事件里写方法 ,事件会定时触发的 。时间可以设定。 定时器 我知道 Winfrom程序中有很多Form阿 比如MainForm-->Form1-->Form2要从Form2返回到MainForm 怎么搞阿 方法不很,定时器比较简单了,上面说了System.Timers.Timer timer = new System.Timers.Timer();timer有自己的循环事件,这个和while差不多,只是不需要多线程处理,好处理循环和下面的while中代码差不多或者用whilebool 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的修改也要加锁,避免崩溃 override on close(){ this.parant.close(); basc.close();}//定义好这个parant 我就是问 //返回Main这里的代码该怎么写阿 你试试这一句话 foreach (Form myForm in Application.OpenForms)// 遍历所有子窗 MessageBox.Show(myForm.Text);写到定时器里,如果不是主窗口,就关闭。我没试,你试一下,看行不行 MainForm-->Form1-->Form2Form2计数器超时,则把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(); } treeview 编辑节点 如何在table的指定td里动态写入一个img客户端控件 请问如何避免数据库select时遇非法字符出错? C#写P2P和网络棋牌游戏有什么好书推荐? 如何在winform下嵌入简单的网页 DIV的问题 哥们帮忙解决,有分啊, 请教一个问题,怎么才能得到改变某个web页面的分辨率的效果,很急呀 sumanden(心头慌,打中张) ,请笑纳100分 在C#中如何读取CPU的工业系列号?(就是那个唯一的编号) 利用反射给属性赋值Convert.ChangeType时出异常 beargo进! 把代码发来吧,谢谢了。
在Timer控件外建立一个变量例如(public static) int num = 0;然后双击建立的Timer控件,在里面写如下代码:num = num + 1;
if(num == 10)
{
关闭代码。
}然后在你的每一次操作的代码中,添加num = 0进行计时的更新。
Winfrom程序中有很多Form阿
比如MainForm-->Form1-->Form2
要从Form2返回到MainForm 怎么搞阿
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的修改也要加锁,避免崩溃
{
this.parant.close();
basc.close();
}//定义好这个parant
//返回Main
这里的代码该怎么写阿
foreach (Form myForm in Application.OpenForms)// 遍历所有子窗
MessageBox.Show(myForm.Text);
写到定时器里,如果不是主窗口,就关闭。
我没试,你试一下,看行不行
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();
}