zoukankan      html  css  js  c++  java
  • winfrom 自动关闭 重写MessageBox.Show("Test");

    复制代码  自动关闭

    调用    AutoClosingMessageBox.Show("添加失败", "提示", 1000);

    #region alert
    public class AutoClosingMessageBox
    {
    System.Threading.Timer _timeoutTimer;
    string _caption;
    AutoClosingMessageBox(string text, string caption, int timeout)
    {
    _caption = caption;
    _timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
    null, timeout, System.Threading.Timeout.Infinite);
    MessageBox.Show(text, caption);

    }
    public static void Show(string text, string caption, int timeout)
    {
    new AutoClosingMessageBox(text, caption, timeout);
    }
    void OnTimerElapsed(object state)
    {
    IntPtr mbWnd = FindWindow(null, _caption);
    if (mbWnd != IntPtr.Zero)
    SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
    _timeoutTimer.Dispose();
    }
    const int WM_CLOSE = 0x0010;
    [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
    static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
    }
    #endregion

  • 相关阅读:
    斐波拉契数列
    判断润年
    欧拉回路
    走迷宫
    八连块问题
    知道一棵二叉树的前序和中序序列求二叉树的后续序列
    判断一个顺序排列的栈的输出序列
    Number Sequence
    如何去设计一个自适应的网页设计或HTMl5
    position
  • 原文地址:https://www.cnblogs.com/whatarey/p/10118726.html
Copyright © 2011-2022 走看看