Automatically close the MessageBox at timed intervals

Source: Internet
Author: User

Using system;using system.collections.generic;using system.componentmodel;using;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.