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", En Trypoint = "FindWindow", CharSet = CharSet.Auto)] private extern static IntPtr FindWindow (string lpclassname, Strin G 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 ("Automatically closes the MessageBox window after 3 seconds", "MessageBox"); } private void Startkiller () {Timer timer = new timer (); Timer. Interval = 3000; 3 seconds to start the timer. Tick + = new EventHandler (Timer_tick); Timer. Start (); private void Timer_tick (object sender, EventArgs e) { Killmessagebox (); Stop the timer ((timer) sender). Stop (); } private void Killmessagebox () {//Follow the header of the MessageBox to find the MessageBox window IntPtr ptr = FINDW Indow (NULL, "MessageBox"); if (ptr! = IntPtr.Zero) {//Find Closes MessageBox window PostMessage (PTR, wm_close, intptr.z Ero, IntPtr.Zero); } } }}
The method that is scouring on the network, experiment is available, notice need to refer to System.Runtime.InteropServices; namespace
Automatically close the MessageBox at timed intervals