MessageBox里的Show里沒(méi)有自動(dòng)關(guān)閉的方法,但是你可以自定義一個(gè)MessageBox,MessageBox就是一個(gè)窗體,你新建一個(gè)窗體Form2,添加一個(gè)public屬性message和一個(gè)定時(shí)器timer1,timer1的interval設(shè)置成你想要的時(shí)間,在Form2的Load事件啟動(dòng)timer1,Timer1_Tick事件里關(guān)閉窗口Me.Close(),然后在需要顯示Messagebox的時(shí)候,在主窗口Form1里設(shè)置messge屬性,然后用show方法彈出窗口就可以了。
十余年的富平網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。成都全網(wǎng)營(yíng)銷的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整富平建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。成都創(chuàng)新互聯(lián)從事“富平網(wǎng)站設(shè)計(jì)”,“富平網(wǎng)站推廣”以來(lái),每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
Form1程序:(添加了一個(gè)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
Form2程序:(添加了一個(gè)Label1顯示信息和一個(gè)Timer1用于計(jì)時(shí),F(xiàn)orm2可以自定義成你想要的樣式,標(biāo)題,按鈕,窗體樣式等)
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 '定時(shí)3秒關(guān)閉窗口
Timer1.Enabled = True
End Sub
End Class
代碼已在VS2017測(cè)試通過(guò)。
這是點(diǎn)擊Option 你可以
用個(gè)msgbox函數(shù) 點(diǎn)擊YES時(shí)候運(yùn)行關(guān)機(jī)代碼即可
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Integer, ByVal dwReserved As Integer) As Integer
Const EWX_FORCE As Short = 4
Const EWX_LOGOFF As Short = 0
Const EWX_REBOOT As Short = 2
Const EWX_SHUTDOWN As Short = 1
Dim retval As Integer
' 定義Esc按鍵
Const VK_ESCAPE As Short = H1Bs
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
If Option1.Checked Then
' 注銷當(dāng)前用戶
retval = ExitWindowsEx(EWX_FORCE, 0) bitsCN.Com
ElseIf Option2.Checked Then
' 關(guān)閉計(jì)算機(jī)
retval = ExitWindowsEx(EWX_SHUTDOWN, 0)
ElseIf Option3.Checked Then
' 重新啟動(dòng)
retval = ExitWindowsEx(EWX_REBOOT, 0)
End If
End Sub
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
Me.Close()
End Sub
' 按Esc鍵時(shí),結(jié)束應(yīng)用程序
Private Sub Form1_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
If KeyAscii = VK_ESCAPE Then BBS.bitsCN.com網(wǎng)管論壇
Me.Close()
End If
If KeyAscii = 0 Then
eventArgs.Handled = True
End If
End Sub
系統(tǒng)托盤(pán)里顯示圖標(biāo)的話用NotifyIcon組件,建立一個(gè)ContextMenuStrip控件與之關(guān)聯(lián)。關(guān)聯(lián)的位置在NotifyIcon.ContextMenuStrip。關(guān)機(jī)直接shell 命令列:rundll32.exe user.exe,exitwindows就可以,聲音提示用My.Compurer.Audio.Play ("路徑"),提示消息用Msgbox函數(shù)……通過(guò)判斷返回值在確定是否關(guān)機(jī)……手頭沒(méi)有VB.Net……大概思路就是這樣,不知道能不能對(duì)你有幫助……如果要代碼的話,不忙的時(shí)候可以給你寫(xiě)
有兩種方法,第一種是調(diào)用shutdown.exe
shell("shutdown.exe路徑
-s
-t
0")
'-t是延遲時(shí)間,0表示立刻關(guān)機(jī)
另一種就是使用API了,好像是ExitWindow,你可以去搜索一下其用法。
Windows
XP的關(guān)機(jī)是由Shutdown.exe程序來(lái)控制的,位于Windows\System32文件夾中。如果想讓W(xué)indows
2000也實(shí)現(xiàn)同樣的效果,可以把Shutdown.exe復(fù)制到系統(tǒng)目錄下。
比如你的電腦要在22:00關(guān)機(jī),可以選擇“開(kāi)始→運(yùn)行”,輸入“at
22:00
Shutdown
-s”,這樣,到了22點(diǎn)電腦就會(huì)出現(xiàn)“系統(tǒng)關(guān)機(jī)”對(duì)話框,默認(rèn)有30秒鐘的倒計(jì)時(shí)并提示你保存工作。如果你想以倒計(jì)時(shí)的方式關(guān)機(jī),可以輸入“Shutdown.exe
-s
-t
3600”,這里表示60分鐘后自動(dòng)關(guān)機(jī),“3600”代表60分鐘。
設(shè)置好自動(dòng)關(guān)機(jī)后,如果想取消的話,可以在運(yùn)行中輸入“shutdown
-a”。另外輸入“shutdown
-i”,則可以打開(kāi)設(shè)置自動(dòng)關(guān)機(jī)對(duì)話框,對(duì)自動(dòng)關(guān)機(jī)進(jìn)行設(shè)置。
Shutdown.exe的參數(shù),每個(gè)都具有特定的用途,執(zhí)行每一個(gè)都會(huì)產(chǎn)生不同的效果,比如“-s”就表示關(guān)閉本地計(jì)算機(jī),“-a”表示取消關(guān)
機(jī)操作,下面列出了更多參數(shù),大家可以在Shutdown.exe中按需使用。
其他的我也不多說(shuō)了,這樣說(shuō)已經(jīng)很詳細(xì)了,你應(yīng)該能看懂。
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long Private Declare Function LookupPrivilegeValue Lib "advapi32" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long Private Declare Function AdjustTokenPrivileges Lib "advapi32" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long Const TOKEN_ADJUST_PRIVILEGES = H20 Const TOKEN_QUERY = H8 Const SE_PRIVILEGE_ENABLED = H2 Private Type LUID UsedPart As Long IgnoredForNowHigh32BitPart As Long End Type Private Type TOKEN_PRIVILEGES PrivilegeCount As Long TheLuid As LUID Attributes As Long End Type Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long Const HELP_CONTENTS = H3 Const EWX_FORCE = 4 '終止沒(méi)有響應(yīng)的進(jìn)程 Const EWX_SHUTDOWN = 8 '關(guān)閉電源 Dim SDTime Private Sub Timer1_Timer() '重新設(shè)置標(biāo)簽時(shí)間 并判斷是否為關(guān)機(jī)時(shí)間 Label1.Caption = Time '判斷時(shí)間是否為關(guān)機(jī)時(shí)間 If Time = SDTime Then '關(guān)閉計(jì)算機(jī) ExitWindowsEx EWX_FORCE Or EWX_SHUTDOWN, 0 End If End Sub Private Sub Command1_Click() SDTime = Text1.Text If SDTime = "" Then Exit Sub '判斷輸入內(nèi)容是否為時(shí)間格式 If Not IsDate(SDTime) Then MsgBox "無(wú)效的時(shí)間格式!" Else '把文本格式的時(shí)間轉(zhuǎn)化為曰期型 SDTime = CDate(SDTime) End If End Sub
希望采納