I'm writing my own extension. I've created a toolbar button. The template I used was "Visual Studio Package" and there was an option during the wizard to create a command button (or something like that)
So the button shows up, but I can't work out how to get the current document or the selected text within the document.
Any help would be appreciated.
There are two ways to approach it:
DTE
to get the current document ( DTE.ActiveDocument
) and selected text ( ((TextDocument)activeDoc).Selection.Text
). You can get the top-level DTE
object in your package by writing: DTE dte = GetService(typeof(SDTE)) as DTE;
Note that the active document may be null
.
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.