我设法创建了一个类,它允许我向任何形式的系统菜单添加一个“关于...”按钮。这部分工作正常,按钮由load
表单事件添加,但是如何处理该按钮的点击?谢谢。
这是我添加按钮的方式 -
Private Sub mainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
{More code....}
Dim SysMenu = New SystemMenu(Me)
{More code....}
End Sub
这是SystemMenu
课程 -
Imports System.Windows.Forms
Public Class SystemMenu
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As IntPtr, ByVal bRevert As Boolean) As IntPtr
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As IntPtr, ByVal uFlags As Int32, ByVal uIDNewItem As IntPtr, ByVal lpNewItem As String) As Boolean
Private Const MF_STRING As Integer = &H0
Private Const MF_SEPARATOR As Integer = &H800
Private m_hSysMenu As IntPtr
Private Property hSysMenu() As IntPtr
Get
Return Me.m_hSysMenu
End Get
Set(ByVal Value As IntPtr)
Me.m_hSysMenu = Value
End Set
End Property
'**
' Constructor
'*
Protected Friend Sub New(ByRef Form As Form)
Me.hSysMenu = GetSystemMenu(Form.Handle, False)
AddAbout(Form)
End Sub
'**
' Add an 'About' button to the system menu of the given form
'*
Private Sub AddAbout(ByRef Form As Form)
AppendMenu(Me.hSysMenu, MF_SEPARATOR, 1000, Nothing)
AppendMenu(Me.hSysMenu, MF_STRING, 1001, "About...")
End Sub
End Class