C # Implementation WinForm automatically close the MessageBox dialog box method

Source: Internet
Author: User

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

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.