国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#實現winform自動關閉MessageBox對話框的方法

2020-01-24 01:55:49
字體:
來源:轉載
供稿:網友

本文實例講述了C#實現winform自動關閉MessageBox對話框的方法。分享給大家供大家參考。具體實現方法如下:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsApplication1 {  public partial class AutoDeleteMessageBox : Form  {   [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;   public AutoDeleteMessageBox()   {    InitializeComponent();   }   private void button1_Click(object sender, EventArgs e)   {    StartKiller();    MessageBox.Show("3秒鐘后自動關閉MessageBox窗口", "MessageBox");   }   private void StartKiller()   {    Timer timer = new Timer();    timer.Interval = 3000; //3秒啟動    timer.Tick += new EventHandler(Timer_Tick);    timer.Start();   }   private void Timer_Tick(object sender, EventArgs e)   {    KillMessageBox();    //停止Timer    ((Timer)sender).Stop();   }   private void KillMessageBox()   {    //按照MessageBox的標題,找到MessageBox的窗口    IntPtr ptr = FindWindow(null, "MessageBox");    if (ptr != IntPtr.Zero)    {     //找到則關閉MessageBox窗口     PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);    }   }  } }

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黑龙江省| 秀山| 比如县| 沙湾县| 涞源县| 义乌市| 六盘水市| 邛崃市| 施甸县| 岳池县| 图们市| 新平| 绵竹市| 新竹县| 清河县| 肥乡县| 循化| 芦山县| 屯门区| 沿河| 永宁县| 马公市| 洱源县| 丽水市| 鲁山县| 通山县| 阿尔山市| 阿拉善盟| 安西县| 滨州市| 尼木县| 喀什市| 江油市| 北辰区| 固安县| 府谷县| 自贡市| 黔东| 七台河市| 休宁县| 乃东县|