Hi
I want to capture mouse events when the mouse is positioned on the title bar of a form. In particular I want to be able to replace the standard context menu (to move, size, maximize, minimize, close) with one of my own.
Can anyone help please?
Hi
I want to capture mouse events when the mouse is positioned on the title bar of a form. In particular I want to be able to replace the standard context menu (to move, size, maximize, minimize, close) with one of my own.
Can anyone help please?
Hi, You have to override Window Procedure for the particular form. I give example that shows Context menu when user right click on the Title bar
Public Const WM_NCRBUTTONDOWN = &HA4
Public Const WM_NCRBUTTONUP = &HA5
Dim ContMenu As ContextMenuStrip
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ContMenu = New ContextMenuStrip()
ContMenu.Items.Add("Open")
ContMenu.Items.Add("Exit")
End Sub
Protected Overrides Sub WndProc(ByRef WndMsg As System.Windows.Forms.Message)
If WndMsg.Msg = WM_NCRBUTTONDOWN Then
ContMenu.Show(Control.MousePosition)
Return ' Prevent to process this Message to the Base Class
End If
MyBase.WndProc(WndMsg)
End Sub
This example just override the Context menu, but still if user click on the Top Left corner or Alt + Space it will show the context menu. If you want to change this menu you have to go for Win32 API.
Many thanks for your reply. I can now do exactly what I wanted to.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.