How can I change the background color of the code window using an add-in?

Hello,

I need to write add-in thats changes code background in code window.
Is there any samples how to do this

I will very glad if somebody help me to do this.
Thank you.


Answer this question

How can I change the background color of the code window using an add-in?

  • Klaus Keith

    Hi Zenit,

    The following macro will change the editor background to Green using the DTE. You should be able to easily do this from an addin with some minor adjustments.

    Thanks,
    AaronM [MSFT]


    Imports System
    Imports System.Drawing
    Imports System.Drawing.Color
    Imports EnvDTE
    Imports EnvDTE80

    Public Module ColorTest
        Sub ChangeBackgroundColor()
            Dim props As EnvDTE.Properties
            props = DTE.Properties("FontsAndColors", "TextEditor")
            Dim prop As EnvDTE.FontsAndColorsItems = props.Item("FontsAndColorsItems").Object
            prop.Item("Plain Text").Background = ColorTranslator.ToOle(System.Drawing.Color.Green)
        End Sub
    End Module

     



  • Peter G Lin

    Hi, Aaron.

    Yes. I mean highlighting.
    User selects text and this text changes background. This background saves after selecting another fragment.

    Can VSIP help with this problem.

    Thank you.



  • Coco King

    Thank you for response Aaron.
    But I want to chnge background of selected text in code window(TextSelection).
    How can I do this

    Thank you, Yan.

  • Vasile

    Hi Zenit,
       If the only thing you need is to programatically change the option for the Selected Text color, you can make a slight change to the code I posted above to access the "Selected Text" property instead of Plain Text.


    Imports System
    Imports System.Drawing
    Imports System.Drawing.Color
    Imports EnvDTE
    Imports EnvDTE80

    Public Module ColorTest
        Sub ChangeBackgroundColor()
            Dim props As EnvDTE.Properties
            props = DTE.Properties("FontsAndColors", "TextEditor")
            Dim prop As EnvDTE.FontsAndColorsItems = props.Item("FontsAndColorsItems").Object
            prop.Item("Selected Text").Background = ColorTranslator.ToOle(System.Drawing.Color.Green)
        End Sub
    End Module

     



    You can of course hook something like this up to the various environment events to respond to user actions. If you are trying to something
    more complicated, please let us know exactly what you're trying to accomplish. Are you looking to create a "highlighting" feature similar to Microsoft Word highlighting Something else perhaps

    Thanks,
    Aaron



  • How can I change the background color of the code window using an add-in?