How can I disable right click on title bar of the form and prevent showing system context menu:
Help me to get out of this issue
thank you
How can I disable right click on title bar of the form and prevent showing system context menu:
Help me to get out of this issue
thank you
If you specifically want to disable showing system context menu on right click on window's title bar, you can handle WM_CONTEXTMENU
:
const int WM_CONTEXTMENU = 0x007B;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_CONTEXTMENU)
m.Result = IntPtr.Zero;
else
base.WndProc(ref m);
}
If you also want to prevent the possibility of clicking on form's icon to show the context menu, then you can set ShowIcon
property of the form to false
:
this.ShowIcon = false;
Have you tried setting your Window Style
property to 'None
'? This should remove the Title Bar's Context Menu completely.
You can achieve this by setting the ControlBox
property of form to false
.
public Form1()
{
InitializeComponent();
this.ControlBox = false;
}
No more Context Menu with Restore, Maximize Minimize, Close, Move will be displayed on Right Clicking on the Title Bar.
this.ControlBox = false;
Note: Above one line (this.ControlBox = false;
), is the key and the Form1 Constructor with InitializeComponent() method call is shown is the sample, just to show the context.