C # Implementation WinForm automatically close the MessageBox dialog box method
This article mainly introduces C # implementation WinForm automatic Shutdown MessageBox dialog box method, example Analysis of C # MessageBox dialog box related operation skills, need friends can refer to the
This article illustrates how C # implements WinForm to automatically close the MessageBox dialog box. Share to everyone for your reference. The implementation methods are as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 This is the |
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) {Startkil Ler (); 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 timer. Tick + = new EventHandler (Timer_tick); Timer. Start (); } private void Timer_tick (object sender, EventArgs e) {killmessagebox ()//Stop Timer ((Timer) sender). Stop (); The private void Killmessagebox () {//follows the MessageBox title to find the MessageBox window IntPtr ptr = FindWindow (null, "MessageBox"); if (PTR! = IntPtr.Zero) {///Find Closes MessageBox window PostMessage (PTR, Wm_close, IntPtr.Zero, IntPtr.Zero);} } } |
I hope this article will help you with your C # program