Override form context menu

Pirahnaplant

Well-known member
Joined
Mar 29, 2009
Messages
75
Programming Experience
3-5
How can I override the context menu that shows up when you right click on the title bar or the icon?
 
Thank you, using that and other information I found, I was able to create a class that can manipulate the system menu. This class is attached.

Add this code to your form to get events from the menu

VB.NET:
    Private SysMenu As New SystemMenu(Me)

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = &H112 Then
            Dim ids() As Integer = SysMenu.GetIDs()
            RaiseEvent SysMenuItemClicked(SysMenu, New ItemClickedEventArgs(Array.IndexOf(ids, m.WParam.ToInt32)))
        End If
        MyBase.WndProc(m)
    End Sub

    Public Event SysMenuItemClicked(ByVal sender As Object, ByVal e As ItemClickedEventArgs)
 

Attachments

  • SystemMenu.zip
    1.8 KB · Views: 17
I have made an updated version if anyone wants to use it. It is attached.

This is the code you should put on your form:

VB.NET:
    Private SysMenu As New SystemMenu(Me)

    Private Const WM_SYSCOMMAND As Integer = &H112

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = WM_SYSCOMMAND Then
            RaiseEvent SysMenuItemClicked(SysMenu, New ItemClickedEventArgs(SysMenu.ItemsID(m.WParam.ToInt32)))
        End If
        MyBase.WndProc(m)
    End Sub

    Public Event SysMenuItemClicked(ByVal sender As Object, ByVal e As ItemClickedEventArgs)
 

Attachments

  • SystemMenu.zip
    2.5 KB · Views: 16
Back
Top