简体   繁体   English

防止在表单标题栏上右键单击显示系统上下文菜单

[英]Prevent showing system context menu on right click on Form title bar

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 :如果您特别想禁用右键单击窗口标题栏时显示系统上下文菜单,您可以处理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 :如果您还想防止单击表单图标以显示上下文菜单的可能性,则可以将表单的ShowIcon属性设置为false

this.ShowIcon = false;

Have you tried setting your Window Style property to ' None '?您是否尝试将Window Style属性设置为“ None ”? This should remove the Title Bar's Context Menu completely.这应该完全删除标题栏的上下文菜单。

You can achieve this by setting the ControlBox property of form to false .您可以通过将表单的ControlBox属性设置为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.注意:上面一行( this.ControlBox = false; )是关键,带有 InitializeComponent() 方法调用的 Form1 构造函数是示例,只是为了显示上下文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM