简体   繁体   English

当我按WindowsLogs + D时,ContextMenustrip不会自动关闭

[英]ContextMenustrip is not closing automatically when i press WindowsLogs+D

I have contextmenustrip named "cmsView" in my application. 我的应用程序中有名为“ cmsView”的contextmenustrip。 When i right click the mouse button the cmsView has opened and click some where in the application cmsView gets closed. 当我右键单击鼠标按钮时,cmsView已打开,然后单击一些在应用程序中cmsView关闭的位置。 If I opened the cmsView and press Windowslogo +D(ie, minimize the applications) and again the cmsView is not closed and in opened state whenever i click some in the application and lost it focus. 如果我打开cmsView并按Windowslogo + D(即,最小化应用程序),则每当我单击应用程序中的某些内容并失去焦点时,cmsView都不会关闭并处于打开状态。

How to solve this issue. 如何解决这个问题。

Regards, Tanya 问候,Tanya

This is not a bug in your application or in the ContextMenuStrip control. 这不是您的应用程序或ContextMenuStrip控件中的错误。 If anything, it's a bug in Windows with the pop-up menu control, and the WinForms controls are actually mimicking that bug so that they will behave as the user expects. 如果有的话,这是Windows中带有弹出菜单控件的错误,而WinForms控件实际上是在模仿该错误,因此它们的行为将符合用户的期望。

You can test this out for yourself in a simple application like Notepad. 您可以在一个简单的应用程序(如记事本)中自己进行测试。 Open a new instance, right-click on the document area, and then press Win + D . 打开一个新实例,右键单击文档区域,然后按Win + D。 The context menu will remain open and visible on the desktop, even though the application's window is gone (minimized). 即使应用程序的窗口已消失(最小化),上下文菜单也将保持打开状态并在桌面上可见。

So I don't recommend trying to "fix" this in your application. 因此,我不建议您尝试在应用程序中“修复”此问题。 When in Rome, do as the Romans do... 在罗马做到入乡随俗...

If you absolutely had to try and fix it, you might try listening for a minimize event for your form and manually instructing the context menu to close. 如果绝对必须尝试修复它,则可以尝试侦听表单的minimize事件并手动指示关闭上下文菜单。

private const int WM_SYSCOMMAND = 0x0112; 
private const int SC_MINIMIZE = 0xf020; 

protected override void WndProc(ref Message m) 
{ 
    if (m.Msg == WM_SYSCOMMAND) 
    { 
        if (m.WParam.ToInt32() == SC_MINIMIZE) 
        { 
            // Close the context menu strip when the form is being minimized
            cmsView.Close();    
        } 
    } 
    base.WndProc(ref m); 
} 

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

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