C#定时关闭窗体实例
本文实例讲述了C#定时关闭窗体的方法,分享给大家供大家参考。具体方法如下:
publicpartialclassForm2:Form { privateSystem.Timers.Timertimer=newSystem.Timers.Timer();
publicForm2() { InitializeComponent(); InitStatus(); timer.Interval=4000; timer.Elapsed+=newSystem.Timers.ElapsedEventHandler(timer_Elapsed); timer.Enabled=true; }
voidtimer_Elapsed(objectsender,System.Timers.ElapsedEventArgse) { IntPtrhDlog=FindWindow(null,"Show"); if(IntPtr.Zero!=hDlog) { IntPtrresult; EndDialog(hDlog,outresult); } }
privatevoidInitStatus() { this.panel1.Controls.Clear();
Form1from1=newForm1(); from1.TopLevel=false; from1.FormBorderStyle=FormBorderStyle.None;
this.panel1.Controls.Add(from1); from1.Show(); } [DllImport("user32.dll",SetLastError=true)] publicstaticexternIntPtrFindWindow(stringlpClassName,stringcaption);