【发布时间】:2013-12-16 17:47:23
【问题描述】:
我已经设法创建了一个类,它允许我将“关于...”按钮添加到任何形式的系统菜单。这部分工作正常,按钮由表单的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
【问题讨论】:
-
我之前发现的。即使包含
Imports System.Windows.Forms.NativeWindow,我仍然收到错误Type 'SubclassedSystemMenu' is not defined.谢谢。
标签: vb.net events systemmenu