Implementing an Automatically Closed MessageBox under WinForm

Realize an automatic closing MessageBox under WinForm Author: eaglet Under WinForm, we can call MessageBox.Show to display a message dialog box, prompting the user to confirm and other operations. In some applications, we need to automatically close the message dialog box through the program instead of the user clicking the confirmation button to close it. However. Net framework does not provide us with a method to automatically close the MessageBox, to achieve this function, we need to use the Window API to complete. First of all, we need to find the window handle of the message dialog box. A relatively simple method is to use the FindWindow API to find the corresponding window handle. [DllImport( “ user32.dll “ , SetLastError = true )] static extern IntPtr FindWindow( string lpClassName, string lpWindowName); This API call can find the window handle by the class name of the window or the name of the window title. Next we need to find an API to close the dialog box, here I use EndDialog [DllImport( “ user32.dll “ )] static extern bool EndDialog(IntPtr hDlg, out IntPtr nResult); With these two API functions, we can close the message dialog box. The idea is to start a…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索