form1.vb
来自「Visual.Basic.NET实用编程百例-47.6M.zip」· VB 代码 · 共 99 行
VB
99 行
Imports System.ComponentModel
Imports System.Drawing
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
Initializenotifyicon()
'设置状态栏图标
End Sub
Private Sub Initializenotifyicon()
NotifyIcon.Icon = New Icon("..\cstrike.ico")
notifyicon.Text = "右击以显示菜单"
notifyicon.Visible = True
'设置默认图标
Dim mnuItms(0) As MenuItem
mnuItms(0) = New MenuItem("退出", _
New EventHandler(AddressOf Me.ExitSelect))
'设置菜单项
Dim notifyiconMnu As ContextMenu = New ContextMenu(mnuItms)
'将所有菜单项对象同时添加到
'上下文菜单中
notifyicon.ContextMenu = notifyiconMnu
'指定notifyicon的上下文菜单为notifyiconMnu
End Sub
Public Sub ExitSelect(ByVal sender As Object, ByVal e As System.EventArgs)
notifyicon.Visible = False
'隐藏任务栏图标
Me.Close()
'闭合
End Sub
'在用户选择“退出”上下文菜单时调用
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Private WithEvents NotifyIcon As System.Windows.Forms.NotifyIcon
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.NotifyIcon = New System.Windows.Forms.NotifyIcon(Me.components)
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'NotifyIcon
'
Me.NotifyIcon.Text = ""
Me.NotifyIcon.Visible = True
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(96, 64)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(100, 30)
Me.Button1.TabIndex = 0
Me.Button1.Text = "退出"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(292, 173)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "在转态栏中加入图标"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End
End Sub
End Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?