zoukankan      html  css  js  c++  java
  • [转]winfrom让弹出的MessageBox在指定时间内自动销毁

    winfrom让弹出的MessageBox在指定时间内自动销毁,代码如下:
    private void Button_Click(object sender, System.EventArgs e)
    {
    StartKiller();
    MessageBox.Show("这里是MessageBox弹出的内容","MessageBox");
    MessageBox.Show("这里是跟随运行的窗口","窗口");
    }

    private void StartKiller()
    {
    Timer timer = new Timer();
    timer.Interval = 10000;//10秒启动
    timer.Tick += new EventHandler(Timer_Tick);
    timer.Start();
    }

    private void Timer_Tick(object sender, EventArgs e)
    {
    KillMessageBox();
    //停止计时器
    ((Timer)sender).Stop();
    }

    private void KillMessageBox()
    {
    //查找MessageBox的弹出窗口,注意对应标题
    IntPtr ptr = FindWindow(null,"MessageBox");
    if(ptr != IntPtr.Zero)
    {
    //查找到窗口则关闭
    PostMessage(ptr,WM_CLOSE,IntPtr.Zero,IntPtr.Zero);
    }
    }

    [DllImport("user32.dll", EntryPoint = "FindWindow", CharSet=CharSet.Auto)]
    private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);

    [DllImport("user32.dll", CharSet=CharSet.Auto)]
    public static extern int PostMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

    public const int WM_CLOSE = 0x10;

    本文来自: IT知道网(http://www.itwis.com) 详细出处参考:http://www.itwis.com/html/net/winform/20080402/1185.html

  • 相关阅读:
    字符串删减
    iOS-AFNetworking与ASIHTTPRequest的区别
    iOS-清理缓存
    iOS-addSubView时给UIView添加效果
    iOS-明杰解决字段冲突,及数组映射
    iOS-开发将文本复制到剪切板
    iOS-加载html字符串
    iOS-UILabel加线
    iOS-获取webView的高度
    iOS-plist文件的写读
  • 原文地址:https://www.cnblogs.com/freeliver54/p/1234230.html
Copyright © 2011-2022 走看看