C#定時關(guān)閉窗體實例
本文實例講述了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#開發(fā)WinForm清空DataGridView控件綁定的數(shù)據(jù)
本文詳細講解了C#開發(fā)WinForm清空DataGridView控件綁定數(shù)據(jù)的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-03-03C#使用SqlDataAdapter對象獲取數(shù)據(jù)的方法
這篇文章主要介紹了C#使用SqlDataAdapter對象獲取數(shù)據(jù)的方法,結(jié)合實例形式較為詳細的分析了SqlDataAdapter對象獲取數(shù)據(jù)具體步驟與相關(guān)使用技巧,需要的朋友可以參考下2016-02-02C#保存listbox中數(shù)據(jù)到文本文件的方法
這篇文章主要介紹了C#保存listbox中數(shù)據(jù)到文本文件的方法,涉及C#操作listbox數(shù)據(jù)的相關(guān)技巧,需要的朋友可以參考下2015-04-04C#調(diào)用mmpeg進行各種視頻轉(zhuǎn)換的類實例
這篇文章主要介紹了C#調(diào)用mmpeg進行各種視頻轉(zhuǎn)換的類,實例分析了C#調(diào)用mmpeg操作視頻文件的技巧,非常具有實用價值,需要的朋友可以參考下2015-03-03