C#定時關(guān)閉窗體實(shí)例
本文實(shí)例講述了C#定時關(guān)閉窗體的方法,分享給大家供大家參考。具體方法如下:
{
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#程序設(shè)計有所幫助。
相關(guān)文章
C# SynchronizationContext以及Send和Post使用解讀
這篇文章主要介紹了C# SynchronizationContext以及Send和Post使用解讀,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-05-05
C#實(shí)現(xiàn)簡單過濾非法字符實(shí)例
這篇文章主要介紹了C#實(shí)現(xiàn)簡單過濾非法字符的方法,涉及C#針對字符串遍歷與判斷的相關(guān)技巧,非常簡單實(shí)用,需要的朋友可以參考下2015-11-11
將ocx文件轉(zhuǎn)換成C#程序引用的DLL文件的辦法
將ocx文件轉(zhuǎn)換成C#程序引用的DLL文件的辦法,需要的朋友可以參考一下2013-03-03
WPF實(shí)現(xiàn)能自由改變形狀的四邊形和六邊形
這篇文章主要為大家詳細(xì)介紹了WPF如何實(shí)現(xiàn)能自由改變形狀的四邊形和六邊形,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-03-03

