C# ***.Show怎么设置3秒后 自动关闭?
public partial class Form1 : Form
public Form1
InitializeComponent;
private void button1_Click(object sender, EventArgs e)
***.Show(Text, Caption, 1000);
public class AutoClosingMessageBox
System.Threading.Timer _timeoutTimer;
string _caption;
AutoClosingMessageBox(string text, string caption, int timeout)
_caption = caption;
_timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
null, timeout, System.Threading.Timeout.Infinite);
***.Show(text, caption);
public static void Show(string text, string caption, int timeout)
new AutoClosingMessageBox(text, caption, timeout);
void OnTimerElapsed(object state)
IntPtr mbWnd = FindWindow(null, _caption);
if (mbWnd != ***.Zero)
SendMessage(mbWnd, WM_CLOSE, ***.Zero, ***.Zero);
_timeoutTimer.Dispose;
const int WM_CLOSE = 0x0010;
[System.Runtime.InteropServices.DllImport(user32.dll, SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[System.Runtime.InteropServices.DllImport(user32.dll, CharSet = System.***.CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);