C#實現(xiàn)winform自動關(guān)閉MessageBox對話框的方法
更新時間:2015年04月24日 15:32:51 作者:令狐不聰
這篇文章主要介紹了C#實現(xiàn)winform自動關(guān)閉MessageBox對話框的方法,實例分析了C#中MessageBox對話框的相關(guān)操作技巧,需要的朋友可以參考下
本文實例講述了C#實現(xiàn)winform自動關(guān)閉MessageBox對話框的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
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秒鐘后自動關(guān)閉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) { //找到則關(guān)閉MessageBox窗口 PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero); } } } }
希望本文所述對大家的C#程序設(shè)計有所幫助。
相關(guān)文章
C#在winform中實現(xiàn)數(shù)據(jù)增刪改查等功能
本篇文章主要是介紹了C#在winform中操作數(shù)據(jù)庫,實現(xiàn)數(shù)據(jù)增刪改查,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11C# BinaryReader實現(xiàn)讀取二進制文件
在 C# 以二進制形式讀取數(shù)據(jù)時使用的是 BinaryReader 類。本文介紹了C# BinaryReader實現(xiàn)讀取二進制文件,感興趣的可以了解一下2021-06-06解決C#運行程序修改數(shù)據(jù)后數(shù)據(jù)表不做更新的問題
近日,在使用C#連接數(shù)據(jù)庫的時候,對數(shù)據(jù)庫中的表做更新后,在當前啟動項目中去顯示表數(shù)據(jù)時雖然會發(fā)生一個更新,但是在結(jié)束程序運行后再去觀察數(shù)據(jù)表中的記錄時發(fā)現(xiàn)并沒有發(fā)生一個變化,所以本文給大家解決一下這個問題,需要的朋友可以參考下2023-08-08