Close Context Menu


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: Close Context Menu

  1. #1
    Join Date
    Dec 2007
    Posts
    7

    Close Context Menu

    Hi,

    I whould like to know if there is a way to hide the context menu, in my windows application the context menu is displayed on hover of a button but when the cursor moves away from the button or off the context menu i need to hide the context menu, i tried using the mouse leave event of the button but the button looses focus immediately when the context menu is displayed. please let me know how do i handle this...

    workarounds:
    tried using a timer to hide the context menu by sendkeys.send("{ESC}") for every 2 secs but unable to find if any item is selected in the contextmenu to retain the menu on selection.

    Thanks in advance
    dev
    Last edited by dev12345; 03-12-2008 at 07:17 AM.

  2. #2
    Join Date
    Sep 2007
    Posts
    86

    RE: Closing Context Menu

    Hello,

    Not sure why you are trying to do this as this is default behaviour in all applications. The context menu will go away automatically when the user gives something else focus.
    John Wiese
    ISV Architect Evangelist - Microsoft
    http://blogs.msdn.com/usisvde

  3. #3
    Join Date
    Dec 2007
    Posts
    7
    I have 4 buttons as menu items and on hover of each button it currently displays a context menu, so when i move the mouse over one button a context menu is displayed and then i have to click some where on the screen and move the mouse over the second botton to see the context menu.

  4. #4
    Join Date
    Sep 2007
    Posts
    86

    re: Close Context Menu

    Not sure I'd recommend that pattern for a UI as it is a little off the norm and may throw off your users. Having buttons in a menubar and context menu's for buttons is not in the Vista User Experience Design Guidelines, which you may want to review to help put together a solid UI for your application.

    That said, if you use the "MouseEnter" event to do a contextMenu.Show() and the "MouseLeave" event to do a contextMenu.Hide() you should be able to accomplish what you want to do.
    John Wiese
    ISV Architect Evangelist - Microsoft
    http://blogs.msdn.com/usisvde

  5. #5
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    I agree with John with respect to design.

    Is there a particular reason why you choose contextmenus for each button?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  6. #6
    Join Date
    Dec 2007
    Posts
    7
    there are 2 menus one with the default menu control (horizontal) and the other is leftnavigation menu which will have these buttons...

    Mouseleave is fired immediately after the mousehover is done because we display a context menu on mousehover and the button looses focus.

    please let me know if there a workaround to handle this...
    Last edited by dev12345; 03-18-2008 at 02:17 AM.

  7. #7
    Join Date
    Sep 2007
    Posts
    86
    I think the problem is that you are using MouseHover instead of MouseEnter. MouseEnter is the counterpart to MouseLeave. So if you show your context menu in MouseEnter and hide it in MouseLeave you should be fine.
    John Wiese
    ISV Architect Evangelist - Microsoft
    http://blogs.msdn.com/usisvde

  8. #8
    Join Date
    Dec 2007
    Posts
    7
    It is the same case even if i show context menu in MouseEnter and hide it in MouseLeave. after mouse enter the context menu is displayed and the button looses focus and the mouse leave event is fired. so a series of events get fired, enter then leave again enter leave.....

Similar Threads

  1. Display context menu for RichTextBox
    By David Chu in forum .NET
    Replies: 0
    Last Post: 09-01-2006, 01:07 PM
  2. Replies: 7
    Last Post: 08-15-2006, 04:21 PM
  3. Disabling right click context menu
    By CFPSoft in forum VB Classic
    Replies: 1
    Last Post: 05-15-2006, 06:34 AM
  4. "Graphical" C# Context menu
    By TabDev in forum .NET
    Replies: 0
    Last Post: 07-27-2005, 08:42 AM
  5. Another context menu problem
    By JetserKing in forum VB Classic
    Replies: 0
    Last Post: 02-15-2005, 03:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center