WinForms - How to call the Window Documents Context Menu
-
27-02-2021 - |
Question
On every windows app there is that context menu that you can access with CTRL+Space bar:
I believe this menu is called the "Window Control Menu", but I am not sure.
It has the following options:
Restore
Move
Size
Minimize
Maximize
Close Alt+F4
Here is a pic:
How can I call this using win forms? My goal is to provide a keyboard shortcut to this menu by hitting alt+spacebar
Thanks.
Solution
Send a message to your own window so that the system menu appears.
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, int lParam);
private void callSysMenu()
{
int point = ((this.Location.Y << 16) | ((this.Location.X) & 0xffff));
SendMessage(this.Handle, 0x313, IntPtr.Zero, point);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow