I've managed to create a Class that allows me to add an 'About...' button to the System Menu of any form. This part works fine, with the button being added by the load
event of the form, but how do I handle clicks of that button? Thanks.
Here is how I'm adding the button -
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
And here is the SystemMenu
class -
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
Check this out. Add the
SubclassedSystemMenu.vb
file to the project and add this to your main formAnd then subscribe to its
LaunchDialog
event and open the formAnd here is the
SubclassedSystemMenu
classEnd Class