我設法創建了一個類,允許我在任何表單的系統菜單中添加「關於...」按鈕。這部分工作正常,該按鈕是由表格的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
http://www.codeproject.com/文章/ 6122/Subclassed-System-Menu – Jeff
我發現早些時候。即使包含'Imports System.Windows.Forms.NativeWindow',我仍然得到'Type'SubclassedSystemMenu'未定義的錯誤。「謝謝。 –