重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
MessageBox里的Show里没有自动关闭的方法,但是你可以自定义一个MessageBox,MessageBox就是一个窗体,你新建一个窗体Form2,添加一个public属性message和一个定时器timer1,timer1的interval设置成你想要的时间,在Form2的Load事件启动timer1,Timer1_Tick事件里关闭窗口Me.Close(),然后在需要显示Messagebox的时候,在主窗口Form1里设置messge属性,然后用show方法弹出窗口就可以了。
十余年的富平网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销的优势是能够根据用户设备显示端的尺寸不同,自动调整富平建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联从事“富平网站设计”,“富平网站推广”以来,每个客户项目都认真落实执行。
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
Form2程序:(添加了一个Label1显示信息和一个Timer1用于计时,Form2可以自定义成你想要的样式,标题,按钮,窗体样式等)
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测试通过。
这是点击Option 你可以
用个msgbox函数 点击YES时候运行关机代码即可
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
' 注销当前用户
retval = ExitWindowsEx(EWX_FORCE, 0) bitsCN.Com
ElseIf Option2.Checked Then
' 关闭计算机
retval = ExitWindowsEx(EWX_SHUTDOWN, 0)
ElseIf Option3.Checked Then
' 重新启动
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键时,结束应用程序
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网管论坛
Me.Close()
End If
If KeyAscii = 0 Then
eventArgs.Handled = True
End If
End Sub
系统托盘里显示图标的话用NotifyIcon组件,建立一个ContextMenuStrip控件与之关联。关联的位置在NotifyIcon.ContextMenuStrip。关机直接shell 命令列:rundll32.exe user.exe,exitwindows就可以,声音提示用My.Compurer.Audio.Play ("路径"),提示消息用Msgbox函数……通过判断返回值在确定是否关机……手头没有VB.Net……大概思路就是这样,不知道能不能对你有帮助……如果要代码的话,不忙的时候可以给你写
有两种方法,第一种是调用shutdown.exe
shell("shutdown.exe路径
-s
-t
0")
'-t是延迟时间,0表示立刻关机
另一种就是使用API了,好像是ExitWindow,你可以去搜索一下其用法。
Windows
XP的关机是由Shutdown.exe程序来控制的,位于Windows\System32文件夹中。如果想让Windows
2000也实现同样的效果,可以把Shutdown.exe复制到系统目录下。
比如你的电脑要在22:00关机,可以选择“开始→运行”,输入“at
22:00
Shutdown
-s”,这样,到了22点电脑就会出现“系统关机”对话框,默认有30秒钟的倒计时并提示你保存工作。如果你想以倒计时的方式关机,可以输入“Shutdown.exe
-s
-t
3600”,这里表示60分钟后自动关机,“3600”代表60分钟。
设置好自动关机后,如果想取消的话,可以在运行中输入“shutdown
-a”。另外输入“shutdown
-i”,则可以打开设置自动关机对话框,对自动关机进行设置。
Shutdown.exe的参数,每个都具有特定的用途,执行每一个都会产生不同的效果,比如“-s”就表示关闭本地计算机,“-a”表示取消关
机操作,下面列出了更多参数,大家可以在Shutdown.exe中按需使用。
其他的我也不多说了,这样说已经很详细了,你应该能看懂。
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 '终止没有响应的进程 Const EWX_SHUTDOWN = 8 '关闭电源 Dim SDTime Private Sub Timer1_Timer() '重新设置标签时间 并判断是否为关机时间 Label1.Caption = Time '判断时间是否为关机时间 If Time = SDTime Then '关闭计算机 ExitWindowsEx EWX_FORCE Or EWX_SHUTDOWN, 0 End If End Sub Private Sub Command1_Click() SDTime = Text1.Text If SDTime = "" Then Exit Sub '判断输入内容是否为时间格式 If Not IsDate(SDTime) Then MsgBox "无效的时间格式!" Else '把文本格式的时间转化为曰期型 SDTime = CDate(SDTime) End If End Sub
希望采纳