简体   繁体   中英

Add custom item to right click menu when user selects text

I want to add a custom menu item to the menu that appears when a user selects some text and right clicks. I searched a lot but did not get any answer. Maybe I did not put in the right keyword.

  1. Is it possible to do this?
  2. If this is possible, I want to do this for all applications in windows whenever the user selects text. Is there a universal way to do it or will have to write code specific to the application?

I am using C#.

I don't think you can do that universally in all windows apps. But it is certainly possible to do in your own app using a popup menu.

I've also tried a way to add an item to the standard ContextMenu and failed. From my point of view, the only solution is to set the TextBox's ContextMenuStrip property to an instance of the ContextMenuStrip class and implement both standard and your custom menu items. It is easy to mimic standard operation, since the TextBox class provides all required methods: Cut, Copy, Paste, SelectAll.

The universal way is basically writing a "custom shell extension". There is an article on CodeProject about how to do this.

自定义外壳扩展

http://www.codeproject.com/Articles/174369/How-to-Write-Windows-Shell-Extension-with-NET-Lang

The other way to do this is to build this into your application. For example you might have a text editor and you'll want to highlight a word and get a definition for that word. To do this you'll need to implement a context menu. The VERY BASIC concept is detailed over on CodeReview.StackExchange.

https://codereview.stackexchange.com/questions/3983/c-programatically-creating-context-menu

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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