📄 设置窗体.vb
字号:
Private Sub 最小化ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 最小化ToolStripMenuItem.Click
If Me.Visible = True Then
StrToItems()
delayTime.Value = delay
Me.Hide()
End If
End Sub
Private Sub 创建开机自动运行()
Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.LocalMachine
subkey = key.CreateSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
subkey.SetValue("定时自动关机", Application.ExecutablePath)
End Sub
Private Sub 删除开机自动运行()
Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.LocalMachine
subkey = key.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
subkey.DeleteValue("定时自动关机")
End Sub
'关闭显示器
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Public Const WM_SYSCOMMAND = &H112
Public Const SC_MONITORPOWER = &HF170
'关闭显示器
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
'Timer1的Tick事件,来监视现在的时间是否应该关机或别的了
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Static nowTime As Date = Now
updataMsg()
If SysTime Then
If (Now <> nowTime) Then
Today = nowTime
TimeOfDay = nowTime
End If
End If
nowTime = nowTime.AddSeconds(1)
If (shutTime <> "") Then
Dim temp1() As String = shutTime.Split(";") 'temp1字符串数组存放shutTime以";"分隔的各个字符子串
Dim temp2() As String, i As Integer 'temp2字符串数组存放temp1某项的字符串以","或":"分隔的字符子串
Dim TimeOut As Boolean = False 'TimeOut存放是否时间到了
For i = 0 To temp1.Length - 1
temp2 = temp1(i).Split(New Char() {",", ":"})
If IsTimeOut(temp2) Then '判断时间是否到了
TimeOut = True
action = temp2(4) '是"关机","注销","重启"
End If
Next
If TimeOut Then '如果时间到
Select Case Mid(action, 1, 4) '根据action肯定命令字符串
Case "关闭计算"
shellText = "shutdown -s -f -t 0"
Case "重启计算"
shellText = "shutdown -r -f -t 0"
Case "注销用户"
shellText = "shutdown -l -f -t 0"
Case "关闭显示"
SendMessage(Me.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, 1)
Exit Sub
Case "锁定计算"
shellText = "rundll32.exe user32.dll, LockWorkStation"
Case "打开文件"
System.Diagnostics.Process.Start(Mid(action, 6, action.Length - 6).Replace(":", ":"))
Exit Sub
Case "提醒信息"
MsgBox(Mid(action, 6, action.Length - 6), , "提醒信息")
Exit Sub
Case "打开网址"
System.Diagnostics.Process.Start(Mid(action, 6, action.Length - 6).Replace(":", ":"))
Exit Sub
End Select
lastTime = delay '倒计时等于延时
Timer2.Start() '倒计时开始
取消窗体.Show() '倒计时窗口打开
Timer1.Stop()
End If
End If
End Sub
'判断时间是否到了
Private Function IsTimeOut(ByRef t() As String) As Boolean
'如果时分秒都相等
If t(1) = CStr(Hour(Now())) And t(2) = CStr(Minute(Now()) And t(3) = Second(Now)) Then
Select Case t(0)
Case "每天"
Return True
Case "今天"
Return True
Case "每周二"
If Weekday(Now) = FirstDayOfWeek.Tuesday Then
Return True
End If
Case "每周六"
If Weekday(Now) = FirstDayOfWeek.Saturday Then
Return True
End If
Case "每周日"
If Weekday(Now) = FirstDayOfWeek.Sunday Then
Return True
End If
Case "每周三"
If Weekday(Now) = FirstDayOfWeek.Wednesday Then
Return True
End If
Case "每周四"
If Weekday(Now) = FirstDayOfWeek.Thursday Then
Return True
End If
Case "每周五"
If Weekday(Now) = FirstDayOfWeek.Friday Then
Return True
End If
Case "每周一"
If Weekday(Now) = FirstDayOfWeek.Monday Then
Return True
End If
Case "每周一至周五"
If Weekday(Now) > FirstDayOfWeek.Sunday And Weekday(Now) < FirstDayOfWeek.Saturday Then
Return True
End If
Case Else
If (t(0) = Today.ToShortDateString) Then
Return True
End If
End Select
End If
Return False
End Function
'刷新Msg控件
Private Sub updataMsg()
Dim xingqi As String = ""
Select Case Weekday(Now)
Case 1
xingqi = "星期天"
Case 2
xingqi = "星期一"
Case 3
xingqi = "星期二"
Case 4
xingqi = "星期三"
Case 5
xingqi = "星期四"
Case 6
xingqi = "星期五"
Case 7
xingqi = "星期六"
End Select
msg.Text = "当前时间" & Now().ToLongDateString & " " & Now().ToLongTimeString & " " & xingqi & " CPU使用" & Format(proTime.NextValue, "#0") & "% 网速" & Format(TotalData.NextValue / 1024, "########0.00") & "KB/S"
Me.NotifyIcon1.Text = msg.Text
End Sub
'倒计时处理事件
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If lastTime = 0 Then '如果时间到
Shell(shellText, AppWinStyle.Hide)
取消窗体.Label1.Text = "正在" & action
Else
取消窗体.Label1.Text = "离" & action & "还有" & lastTime & "秒" '显示倒计时
lastTime -= 1
End If
End Sub
Private Sub 设置窗体_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
If autoHide Then
Me.Hide()
End If
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
Select Case ComboBox2.SelectedItem
Case "打开网址"
Button1.Visible = False
TextBox1.Width = 299
TextBox1.Visible = True
Case "提醒信息"
Button1.Visible = False
TextBox1.Width = 299
TextBox1.Visible = True
Case "打开文件"
Button1.Visible = True
TextBox1.Width = 209
TextBox1.Visible = True
Case Else
Button1.Visible = False
TextBox1.Visible = False
End Select
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedItem = "指定日期" Then
DateTimePicker1.Visible = True
Else
DateTimePicker1.Visible = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
TextBox1.Text = OpenFileDialog1.FileName
End If
End Sub
Private Sub 立即关机ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 立即关机ToolStripMenuItem.Click
Shell("shutdown -s -f -t 0")
End Sub
Private Sub 立即重启ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 立即重启ToolStripMenuItem.Click
Shell("shutdown -r -f -t 0")
End Sub
Private Sub 立即注销ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 立即注销ToolStripMenuItem.Click
Shell("shutdown -l -f -t 0")
End Sub
Private Sub 立即锁定计算机ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 立即锁定计算机ToolStripMenuItem.Click
Shell("rundll32.exe user32.dll, LockWorkStation")
End Sub
Private Sub 立即关闭显示器ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 立即关闭显示器ToolStripMenuItem.Click
SendMessage(Me.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, 1)
End Sub
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
System.Diagnostics.Process.Start("http://lywang.5d6d.com/space-uid-1.html")
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -