欢迎来到代码驿站!

.NET代码

当前位置:首页 > 软件编程 > .NET代码

C#定时关闭窗体实例

时间:2021-08-09 08:51:20|栏目:.NET代码|点击:

本文实例讲述了C#定时关闭窗体的方法,分享给大家供大家参考。具体方法如下:

复制代码 代码如下:
public partial class Form2 : Form 

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 style="white-space:pre">  <span style="font-family: monospace; white-space: pre; background-color: rgb(240, 240, 240); ">[DllImport("user32.dll",SetLastError=true)]</span><br style="font-family: monospace; white-space: pre; background-color: rgb(240, 240, 240); "><span style="font-family: monospace; white-space: pre; background-color: rgb(240, 240, 240); ">        public static extern int PostMessage(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam);</span> 
</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#程序设计有所帮助。

上一篇:详解二维码生成工厂

栏    目:.NET代码

下一篇:ASP.net 路径问题 详细说明

本文标题:C#定时关闭窗体实例

本文地址:http://www.codeinn.net/misctech/165449.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有