PublicClass Form1Class Form1 PrivateDeclareFunction FindWindow()Function FindWindow Lib"user32.dll"Alias"FindWindowA" (ByVal lpClassName AsString, ByVal lpWindowName AsString) As Int32 PrivateDeclareFunction PostMessage()Function PostMessage Lib"user32.dll"Alias"PostMessageA" (ByVal hWnd As IntPtr, ByVal msg AsInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) AsInteger Const WM_CLOSE =&H10 Private tmr As Timers.Timer PrivateSub Button1_Click()Sub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click StartKiller() MsgBox("我会在3秒钟后自动关闭!", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "TestMsgBox") End Sub PrivateSub StartKiller()Sub StartKiller() tmr =New Timers.Timer(3000) AddHandler tmr.Elapsed, AddressOf Timer_Tick tmr.Start() End Sub PrivateSub KillMsgBox()Sub KillMsgBox() Dim ptr As IntPtr = FindWindow(Nothing, "TestMsgBox") If ptr <> IntPtr.Zero Then PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero) End Sub PrivateSub Timer_Tick()Sub Timer_Tick(ByVal sender AsObject, ByVal e As Timers.ElapsedEventArgs) KillMsgBox() tmr.Stop() End Sub End Class