c#中在规定时间弹出窗体
来源:百度知道 编辑:UC知道 时间:2024/06/05 09:37:43
我希望能给出来完整的代码 我是初学 ,,是winform程序~~
在 一个 Form 里拖 两个控件 Lable, Timer, 修改Timer属性.Enable=true,Interval=1000.
Id 不改保持默认。
在窗体类写一下代码:
const int closeTime = 5;//关闭程序时间,秒
const int workTime = 10;//弹出窗口所需时间,秒
int curWorkTime = 0; //当前时间,秒
bool needExit = false;// 是否是关闭程序,若不是则表示弹出窗口。
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
curWorkTime++;
if (needExit)
{
label1.Text = string.Concat("剩余 ", closeTime - curWorkTime, " 秒,关闭程序。");
if (curWorkTime == closeTime)//关闭程序
{
Application.Exit();
}
}
else
{
label1.Text = string.Concat("剩余 ", workTime - curWorkTime, "