Search code examples
c#visual-studiopluginsvisual-studio-2015add-in

C# visual studio 2015 extension for inserting code in texteditor


I need to make extension in VS 2015 and find a way to insert code in texteditor. For example, I made add-in, and when I pull over button, it's automatically added in xmltext editor () and/or in designer code (private System.Windows.Forms.Button btnSnimi;).

I made add-in with alerts, and I want to insert alerts from add-in in place in code that I selected, just like buttons.

Is it possible? And some suggestions?


Solution

  • You can use the following code to insert text to the current text editor:

    EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
    ts.Text = "private System.Windows.Forms.Button btnSnimi;";