简体   繁体   中英

Visual Studio Addin - 1. How to Add a context menu? 2. How to get caret position

I'm writing a (very) simple Visual Studio addin. Two things that would make it work nicer are:

  1. A context menu.

  2. Knowing the caret position in the current document (so I can inject text at that position).

Any ideas?

To add a context menu to your addin, you create a CommandBarPopup from:

_applicationObject.CommandBars["Code Window"]

You can view a sample here .

The second part of your question is a little simpler, the current "selection" (or insertion point) is handled by:

(TextSelection)_applicationObject.ActiveDocument.Selection

"_applicationObject" is an instance the DTE Application object created by the add-in project wizard.

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