c#中在規定時間彈出表單

來源:互聯網
上載者:User
文章目錄
  • 問題補充:
我現在做了一個幼兒教育軟體~我想在規定時間提醒他關閉程式 該休息休息 了!如果他還不管3分鐘內強制關閉~?請問這個該怎麼弄謝謝你們?
問題補充:
我希望能給出來完整的代碼 我是初學 ,,是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, " 秒,快顯視窗。");
if (curWorkTime == workTime)//快顯視窗。
{
curWorkTime = 0;
needExit = true;
MessageBox.Show("您該休息了。");
needExit = false;
curWorkTime = 0;
}
}
}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.