开发者

ContextMenustrip is not closing automatically when i press WindowsLogs+D

I have contextmenustrip named "cmsView" in my application. When i right click the mouse button the cmsView has opened and click some where in the app开发者_如何学运维lication cmsView gets closed. If I opened the cmsView and press Windowslogo +D(i.e, 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.


This is not a bug in your application or in the ContextMenuStrip control. 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.

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. 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.

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); 
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜