locked
VS2010: Replacing the editor's context menu with a custom one RRS feed

  • Question

  • Is it possible to replace the editor's context menu  (or project's context menu) with a custom context menu in VS2010?  I have found samples showing how to replace tool tips and Intellisense prompts with custom controls, but have not had any luck finding anything regarding doing the same for the context menu.

    Thank you.

    Wednesday, April 21, 2010 9:29 PM

Answers

  • Hi Vcomrhencke,

    Thanks for your post.

    If you write custom language service, you can replace the editor's context menu with a custom context menu using SHOWCONTEXTMENU command which sents when the user right-clicks. To include your own commands on context menu, handle the command and display a shortcut menu yourself. For more information, please see:

    Important Commands for Language Service Filters

    But if you want to replace current editor's context menu with a custom one, as far as I know, it's not supported. The command filter of editor only intercept some keyboard messages which reach the editor window's message proc. It can't intercept mouse message. Please check How to intercept key presses in the Visual Studio text editor for detailed.

    As a workaround, you can add custom menu items to context menus inside the Visual Studio, for samples, see an article in CodePorject:

    Adding Menu Items to context menus inside the Visual Studio .NET IDE

    If I misunderstood you, or you have any comments, please feel free to let me know.

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by vcomrhencke Thursday, April 22, 2010 4:20 PM
    Thursday, April 22, 2010 4:04 AM

All replies

  • Hi Vcomrhencke,

    Thanks for your post.

    If you write custom language service, you can replace the editor's context menu with a custom context menu using SHOWCONTEXTMENU command which sents when the user right-clicks. To include your own commands on context menu, handle the command and display a shortcut menu yourself. For more information, please see:

    Important Commands for Language Service Filters

    But if you want to replace current editor's context menu with a custom one, as far as I know, it's not supported. The command filter of editor only intercept some keyboard messages which reach the editor window's message proc. It can't intercept mouse message. Please check How to intercept key presses in the Visual Studio text editor for detailed.

    As a workaround, you can add custom menu items to context menus inside the Visual Studio, for samples, see an article in CodePorject:

    Adding Menu Items to context menus inside the Visual Studio .NET IDE

    If I misunderstood you, or you have any comments, please feel free to let me know.

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by vcomrhencke Thursday, April 22, 2010 4:20 PM
    Thursday, April 22, 2010 4:04 AM
  • Thank you, Nancy!

    I was looking to experiment with alternatives interfaces to the context menu in Visual Studio.  It sounds like creating a simple custom language service is my best bet at experimenting here.

    Thank you for your help! 

    Thursday, April 22, 2010 4:22 PM
  • But if you want to replace current editor's context menu with a custom one, as far as I know, it's not supported. The command filter of editor only intercept some keyboard messages which reach the editor window's message proc. It can't intercept mouse message. Please check How to intercept key presses in the Visual Studio text editor for detailed.

    hmmmmmm...... the custom editor  is actually a window, and it will also host another window as the main UI control. If you are familiar with windows API, you will know that each window has registered as a message consumer in message pump. So,, to receive a mouse right click event, you need to override the WndProc method of your control class, and implement your code for WM_LBUTTONDOWN.

    This way you will be able to show a custom context menu within your editor.

    hope this helps ;-)


    Thanks, B.C.
    Friday, April 23, 2010 2:11 PM
  • Thank you, Bo,Chen. :)  I will try that, too!
    Friday, April 23, 2010 3:18 PM