MessageBox里的Show里沒有自動(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方法彈出窗口就可以了。
創(chuàng)新互聯(lián)公司自2013年起,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都做網(wǎng)站、網(wǎng)站制作網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元汝州做網(wǎng)站,已為上家服務(wù),為汝州各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:028-86922220
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ò)。
最近在網(wǎng)上搜索了一些關(guān)于實(shí)現(xiàn)關(guān)機(jī) 重啟 注銷的文章 發(fā)現(xiàn)大多介紹的是VB NET 用API實(shí)現(xiàn)這些功能 且在XPsp 環(huán)境下無(wú)法正常的關(guān)機(jī)與注銷 而對(duì)于VB NET 的介紹幾乎沒有 本文章所涉及的知識(shí)點(diǎn)有
用實(shí)現(xiàn)關(guān)機(jī) 重空坦啟 注銷功能 通過(guò)使用textbox與timer控件的結(jié)合編寫定時(shí)器功能 為你的程序加上超鏈接
本篇文章具有一定的基礎(chǔ)性和廣泛的實(shí)用性 相信能夠給 初薯虧叢學(xué)者帶來(lái)一定的幫助
本文所使用的編程環(huán)境是Microsoft Visual Studio 首先打開 Visual Studio 在文件 (File) 菜單上 單擊新建項(xiàng)目 (New Project) 在新建項(xiàng)目 (New Project) 對(duì)話框的模板 (Templates) 窗格中 單擊 Windows 應(yīng)用程序 (Windows Application) 單擊確定 (OK)
具體步驟如下
首先在Form 窗體數(shù)櫻上添加一個(gè)Label 控件屬性text設(shè)置為:今天: 然后分別添加 個(gè)button控件name分別為button button button 它們的text屬性分別為 關(guān)閉計(jì)算機(jī)(啟動(dòng)定時(shí)器) 注銷 重新啟動(dòng)
圖
現(xiàn)在我們就需要為程序加上一個(gè)定時(shí)器了 這個(gè)定時(shí)器需要與textbox 控件相關(guān)聯(lián) 輸入正確時(shí)間格式后就可以啟動(dòng)定時(shí)功能了 然后我們需要在窗體上添加一個(gè)timer 一個(gè)textbox 控件 和一個(gè)RadioButton 控件 讓它們保留默認(rèn)值不變 其中 TextBox 控件的text屬性設(shè)置為 : : RadioButton 控件text設(shè)置為 指定時(shí)間關(guān)機(jī)|時(shí)間格式 小時(shí): 分鐘: 秒如圖 所示
圖
以上界面工作基本完成現(xiàn)在需要輸入代碼了
雙擊窗體進(jìn)入常規(guī) 聲明Public Class Form 事件中
CODE
Imports System Runtime InteropServicesImports Microsoft VisualBasicPublic Class Form _ 調(diào)用系統(tǒng)參數(shù)Friend Shared Function GetCurrentProcess() As IntPtrEnd Function
_Friend Shared Function OpenProcessToken(ByVal h As IntPtr
ByVal acc As Integer ByRef phtok As IntPtr) As BooleanEnd Function
_Friend Shared Function LookupPrivilegeValue(ByVal host As String
ByVal name As String ByRef pluid As Long) As BooleanEnd Function
_Friend Shared Function AdjustTokenPrivileges(ByVal htok As IntPtr
ByVal disall As Boolean ByRef newst As TokPriv Luid
ByVal len As Integer ByVal prev As IntPtr
ByVal relen As IntPtr) As BooleanEnd Function
_Friend Shared Function ExitWindowsEx(ByVal flg As Integer
ByVal rea As Integer) As BooleanEnd Function
Friend Const SE_PRIVILEGE_ENABLED As Integer = H Friend Const TOKEN_QUERY As Integer = H Friend Const TOKEN_ADJUST_PRIVILEGES As Integer = H Friend Const SE_SHUTDOWN_NAME As String = SeShutdownPrivilege Friend Const EWX_LOGOFF As Integer = H 注銷計(jì)算機(jī)Friend Const EWX_SHUTDOWN As Integer = H 關(guān)閉計(jì)算機(jī)Friend Const EWX_REBOOT As Integer = H 重新啟動(dòng)計(jì)算機(jī)Friend Const EWX_FORCE As Integer = H 關(guān)閉所有進(jìn)程 注銷計(jì)算機(jī)Friend Const EWX_POWEROFF As Integer = H Friend Const EWX_FORCEIFHUNG As Integer = H
_ 引用參數(shù) Friend Structure TokPriv Luid Public Count As Integer Public Luid As Long Public Attr As IntegerEnd Structure
Private Shared Sub DoExitWin(ByVal flg As Integer) Dim xc As Boolean 判斷語(yǔ)句 Dim tp As TokPriv Luid Dim hproc As IntPtr = GetCurrentProcess() 調(diào)用進(jìn)程值 Dim htok As IntPtr = IntPtr Zero xc = OpenProcessToken(hproc TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY htok) tp Count = tp Luid = tp Attr = SE_PRIVILEGE_ENABLED xc = LookupPrivilegeValue(Nothing SE_SHUTDOWN_NAME tp Luid) xc = AdjustTokenPrivileges(htok False tp IntPtr Zero IntPtr Zero) xc = ExitWindowsEx(flg )End Sub
Public Shared Sub Reboot() DoExitWin((EWX_FORCE Or EWX_REBOOT)) 重新啟動(dòng)計(jì)算機(jī)End Sub
Public Shared Sub PowerOff() DoExitWin((EWX_FORCE Or EWX_POWEROFF)) 關(guān)閉計(jì)算機(jī)End Sub
Public Shared Sub LogoOff() DoExitWin((EWX_FORCE Or EWX_LOGOFF)) 注銷計(jì)算機(jī)End Sub
Dim entTime As Object 保存輸入時(shí)間Dim xianzaiTime As Object 保存實(shí)時(shí)時(shí)間Dim startTime As Object 保存開始定時(shí)時(shí)間
注銷button 按鈕輸入code
Private Sub Button _Click(ByVal sender As System Object
ByVal e As System EventArgs) Handles Button ClickLogoOff() 注銷計(jì)算機(jī)End Sub
雙擊重新啟動(dòng)按鈕button 輸入code
Private Sub Button _Click(ByVal sender As System Object
ByVal e As System EventArgs) Handles Button Click
Reboot()
End Sub
雙擊關(guān)閉計(jì)算機(jī)按鈕button 輸入code
Private Sub Button _Click(ByVal sender As System Object
ByVal e As System EventArgs) Handles Button Click startTime = TimeOfDay If Not IsDate(TextBox Text) Then 用IsData函數(shù)判斷輸入的時(shí)間格式MsgBox( 你所輸入的不是時(shí)間格式 ! 錯(cuò)誤 ) ElseentTime = TimeValue(TextBox Text) End If Timer Enabled = True 啟動(dòng)定時(shí)器 Me WindowState = System Windows Forms FormWindowState Minimized 最小化窗體
End Sub
如圖
圖
雙擊timer 控件如圖
圖
輸入代碼
Private Sub Timer _Tick(ByVal sender As System Object
ByVal e As System EventArgs) Handles Timer Tick xianzaiTime = TimeOfDay If RadioButton Checked Then
If DateDiff(Microsoft VisualBasic DateInterval Second
xianzaiTime entTime) Then 用DateDiff函數(shù)判斷是否到時(shí)間了
End IfEnd If
PowerOff() 關(guān)閉計(jì)算機(jī)End Sub
好了 基本上一個(gè)定時(shí)關(guān)機(jī)程序就完成了 接下來(lái)加一個(gè)超級(jí)鏈接吧!當(dāng)然對(duì)于高手來(lái)說(shuō)可能是廢話 但是對(duì)于新手來(lái)說(shuō)這也是必備的 這個(gè)超級(jí)鏈接當(dāng)然是我們最喜歡的天極網(wǎng)開發(fā)頻道了
先創(chuàng)建一個(gè)Label控件吧 把它托到窗體上 將text屬性設(shè)置為天極網(wǎng)開發(fā)頻道如圖
圖
接下來(lái)需要輸入代碼了 雙擊窗體Form
進(jìn)入Public Class Form 事件
代碼
Private Declare Function ShellExecute Lib shell dll
Alias ShellExecuteA (ByVal hwngnd As Integer
ByVal lpOperation As String ByVal lpFile As String
ByVal lpParameters As String ByVal lpDirectory As String
ByVal nShowCmd As Integer) As Integer
如圖
圖
雙擊剛才添加的label屬性text:(天極網(wǎng)開發(fā)頻道)中輸入以下代碼
Private Sub Label _Click(ByVal sender As System Object
ByVal e As System EventArgs) Handles Label ClickShellExecute( open CStr( ) CStr( ) )
End SubEnd Class
OK!全部搞定 按F 鍵運(yùn)行如圖 所示 選擇相應(yīng)選項(xiàng)后點(diǎn)擊(關(guān)閉計(jì)算機(jī)啟動(dòng)定時(shí)器按鈕)就可以了 現(xiàn)在程序?qū)凑漳闼O(shè)定的時(shí)間而啟動(dòng)關(guān)閉計(jì)算機(jī)選項(xiàng)
lishixinzhi/Article/program/net/201311/12366
;???輸入代碼 Private Sub Timer _Tick(ByVal sender As System Object ByVal e As System EventArgs) Handles Timer Tick xianzaiTime = TimeOfDay If RadioButton Checked Then If DateDiff(Microsoft VisualBasic DateInterval Second xianzaiTime entTime) Then 用DateDiff函數(shù)判斷是否到時(shí)間了 End IfEnd IfPowerOff() 關(guān)閉計(jì)算機(jī)End Sub好了基本上一個(gè)定時(shí)關(guān)機(jī)程序就完成了 接下來(lái)加一個(gè)超級(jí)鏈接吧!當(dāng)然腔虛埋對(duì)于高手來(lái)說(shuō)可是廢話 但是對(duì)于新手來(lái)說(shuō)這也是必備的 這個(gè)超級(jí)鏈接當(dāng)然是我們最喜歡的天極網(wǎng)開發(fā)頻道了 先創(chuàng)建一個(gè)譽(yù)晌Label控件吧 把它托到窗體上 將text屬性設(shè)伍螞置為天極網(wǎng)開發(fā)頻道如圖 接下來(lái)需要輸入代碼了 雙擊窗體Form 進(jìn)入Public Class Form 事件代碼 Private Declare Function ShellExecute Lib shell dll Alias ShellExecuteA (ByVal hwngnd As Integer ByVal lpOperation As String ByVal lpFile As String ByVal lpParameters As String ByVal lpDirectory As String ByVal nShowCmd As Integer) As Integer如圖 雙擊剛才添加的label屬性text:(天極網(wǎng)開發(fā)頻道)中輸入以下代碼 Private Sub Label _Click(ByVal sender As System Object ByVal e As System EventArgs) Handles Label ClickShellExecute( open //dev yesky CStr( ) CStr( ) )End SubEnd ClassOK全部搞定 按F 鍵運(yùn)行如圖 所示 選擇相應(yīng)選項(xiàng)后點(diǎn)擊(關(guān)閉計(jì)算機(jī)啟動(dòng)定時(shí)器按鈕)就可以了 現(xiàn)在程序?qū)凑漳闼O(shè)定的時(shí)間而啟動(dòng)關(guān)閉計(jì)算機(jī)選項(xiàng) 圖 lishixinzhi/Article/program/net/201311/15693
1、開機(jī)進(jìn)入桌面后,按下“Windows徽標(biāo)鍵+I”鍵,選中并打開“控制面板”
2、在“控制面板”中的“系統(tǒng)和安全”里,選中“管理工具”里的“計(jì)劃任務(wù)”,并打開“計(jì)劃任務(wù)”
3、在“任務(wù)計(jì)劃程序”里,打開“創(chuàng)建任務(wù)”
4、在“創(chuàng)建卜斗肆任務(wù)”的“常規(guī)”中,根據(jù)相應(yīng)需求設(shè)置,比如“名稱:定時(shí)關(guān)機(jī)”型轎
5、在“創(chuàng)建任務(wù)”的“觸發(fā)器”中,點(diǎn)“新建”,并在“新建觸發(fā)器”中,根據(jù)相應(yīng)需求設(shè)置后,點(diǎn)“確定”
6、在“創(chuàng)建任務(wù)”的“操作”中,點(diǎn)“新建”,并在“新建操作”中的“程序或銷山腳本”里,根據(jù)下圖依次輸入“shutdown”和“-s”后,“點(diǎn)“確定”
7、在“創(chuàng)建任務(wù)”的“條件”中,根據(jù)相應(yīng)需求設(shè)置
8、在“創(chuàng)建任務(wù)”的“設(shè)置”中,根據(jù)相應(yīng)需求設(shè)置后,點(diǎn)“確定”
9、這時(shí)“定時(shí)關(guān)機(jī)”的任務(wù)已創(chuàng)建完成!
網(wǎng)站名稱:vb點(diǎn)虐
定時(shí)的簡(jiǎn)單介紹
標(biāo)題鏈接:http://jinyejixie.com/article44/ddpgche.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、網(wǎng)站策劃、手機(jī)網(wǎng)站建設(shè)、云服務(wù)器、品牌網(wǎng)站制作、小程序開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)