弹出一个对话框 一定时间后 自动消失.
调 用: AutoClosingMessageBox.Show(Now.ToString, "FFFFFFFFFFFFFFFFFF", 3000)
部分:类代码:Imports System.Windows.Forms
Imports System
Public Class AutoClosingMessageBox
Private _timeoutTimer As System.Threading.Timer
Private _caption As String
Private Sub New(ByVal text As String, ByVal caption As String, ByVal timeout As Integer)
_caption = caption
_timeoutTimer = New System.Threading.Timer(AddressOf OnTimerElapsed, Nothing, _
timeout, System.Threading.Timeout.Infinite)
MessageBox.Show(text, caption)
End Sub
Public Shared Sub Show(ByVal text As String, ByVal caption As String, ByVal timeout As Integer)
Dim MsgSow As AutoClosingMessageBox = New AutoClosingMessageBox(text, caption, timeout)
End Sub
Private Sub OnTimerElapsed(ByVal state As Object)
Dim mbWnd As IntPtr = FindWindow(Nothing, _caption)
If mbWnd <> IntPtr.Zero Then
SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero)
End If
_timeoutTimer.Dispose()
End Sub
评论