MessageBox裡的Show裡沒有自動關閉的方法,但是你可以自定義一個MessageBox,MessageBox就是一個窗體,你新建一個窗體Form2,新增一個public屬性message和一個定時器timer1,timer1的interval設定成你想要的時間,在Form2的Load事件啟動timer1,Timer1_Tick事件裡關閉視窗Me.Close(),然後在需要顯示Messagebox的時候,在主視窗Form1裡設定messge屬性,然後用show方法彈出視窗就可以了。
Form1程式:(添加了一個Button1)
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim f2 As Form2 = New Form2
f2.Message = "提示"
f2.ShowDialog()
End Sub
End Class
Public Class Form2
"自定義屬性 顯示提示資訊
Public WriteOnly Property Message As String
Set(value As String)
Label1.Text = value
End Set
End Property
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Me.Close()
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Interval=3000 "定時3秒關閉視窗
Timer1.Enabled = True
程式碼已在VS2017測試透過。
MessageBox裡的Show裡沒有自動關閉的方法,但是你可以自定義一個MessageBox,MessageBox就是一個窗體,你新建一個窗體Form2,新增一個public屬性message和一個定時器timer1,timer1的interval設定成你想要的時間,在Form2的Load事件啟動timer1,Timer1_Tick事件裡關閉視窗Me.Close(),然後在需要顯示Messagebox的時候,在主視窗Form1裡設定messge屬性,然後用show方法彈出視窗就可以了。
Form1程式:(添加了一個Button1)
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim f2 As Form2 = New Form2
f2.Message = "提示"
f2.ShowDialog()
End Sub
End Class
Public Class Form2
"自定義屬性 顯示提示資訊
Public WriteOnly Property Message As String
Set(value As String)
Label1.Text = value
End Set
End Property
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Me.Close()
End Sub
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Interval=3000 "定時3秒關閉視窗
Timer1.Enabled = True
End Sub
End Class
程式碼已在VS2017測試透過。