Public Class Form1
Dim SystemExitFlag = False
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = "俺是农民,俺怕谁???"
RichTextBox1.AppendText(TextBox1.Text)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ToolStripStatusLabel3.Text = DateTime.Now.ToString()
If ToolStripProgressBar1.Value < ToolStripProgressBar1.Maximum Then
ToolStripProgressBar1.Value = ToolStripProgressBar1.Value + ToolStripProgressBar1.Step
Else
ToolStripProgressBar1.Value = ToolStripProgressBar1.Minimum
End If
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
Me.Visible = Not Me.Visible '隐藏/显示窗体转换
If Me.Visible Then '准备显示窗体
'防止最小化不正常显示窗体
NotifyIcon1.Icon = System.Drawing.Icon.ExtractAssociatedIcon("Hot.ico")
Me.WindowState = System.Windows.Forms.FormWindowState.Normal
Else
NotifyIcon1.Icon = System.Drawing.Icon.ExtractAssociatedIcon("Power.ico")
End If
End Sub
Private Sub NotifyIcon1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseClick
'鼠标右键系统托盘事件处理
ContextMenuStrip1.Visible = e.Button = MouseButtons.Right '点击鼠标右键后显示菜单
End Sub
Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs)
'在Resize事件处理中拦截最小最大消息到托盘
Select Case Me.WindowState
Case FormWindowState.Maximized, FormWindowState.Minimized
Me.WindowState = System.Windows.Forms.FormWindowState.Normal
Me.Visible = False '隐藏窗体转换
NotifyIcon1.Icon = System.Drawing.Icon.ExtractAssociatedIcon("Power.ico") '显示隐藏的托盘图标
End Select
End Sub
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If SystemExitFlag = True AndAlso MessageBox.Show("请您确认是否退出(Y/N)", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = DialogResult.Yes Then
e.Cancel = False '托盘退出菜单允许退出系统
Else
e.Cancel = True '最小最大关闭菜单退出钮都会阻止退出系统
Me.WindowState = System.Windows.Forms.FormWindowState.Normal
Me.Visible = False '隐藏窗体转换
NotifyIcon1.Icon = System.Drawing.Icon.ExtractAssociatedIcon("Power.ico") '显示隐藏的托盘图标
'MessageBox.Show("请从系统托盘中退出!!!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
End If
End Sub
Private Sub 退出ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 退出ToolStripMenuItem.Click
ToolStripStatusLabel2.Text = "非法退出"
SystemExitFlag = False
Close() '退入托盘
End Sub
Private Sub 退出ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 退出ToolStripMenuItem1.Click
ToolStripStatusLabel2.Text = "正常退出"
SystemExitFlag = True
Close() '退出系统
End Sub
Private Sub 关于ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 关于ToolStripMenuItem.Click
'System.Diagnostics.Process.Start("Explorer", "http:\\www.hotpage.net.cn")'运行IE
System.Diagnostics.Process.Start("http:\\www.hotpage.net.cn") '自动启动IE
End Sub
Private Sub 我不会VBToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 我不会VBToolStripMenuItem.Click
System.Diagnostics.Process.Start("http:\\www.hotpower.org") '自动启动IE
End Sub
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
文章评论(0条评论)
登录后参与讨论