C#定时关闭窗体实例
本文实例讲述了c#定时关闭窗体的方法,分享给大家供大家参考。具体方法如下:
{
private system.timers.timer timer = new system.timers.timer();
public form2()
{
initializecomponent();
initstatus();
timer.interval = 4000;
timer.elapsed += new system.timers.elapsedeventhandler(timer_elapsed);
timer.enabled = true;
}
void timer_elapsed(object sender, system.timers.elapsedeventargs e)
{
intptr hdlog = findwindow(null, "show");
if (intptr.zero != hdlog)
{
intptr result;
enddialog(hdlog, out result);
}
}
private void initstatus()
{
this.panel1.controls.clear();
form1 from1 = new form1();
from1.toplevel = false;
from1.formborderstyle = formborderstyle.none;
this.panel1.controls.add(from1);
from1.show();
}
[dllimport("user32.dll",setlasterror=true)]
public static extern intptr findwindow(string lpclassname, string caption);
</span>
[dllimport("user32.dll",setlasterror=true)]
public static extern bool enddialog(intptr hdlg, out intptr nresult);
private void button1_click(object sender, eventargs e)
{
messagebox.show("corning", "show");
}
}
希望本文所述对大家的c#程序设计有所帮助。