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
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?
How can I change the background color of the code window using an add-in?
Rasmus Foged
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.
MFred
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
cptkhoa
But I want to chnge background of selected text in code window(TextSelection).
How can I do this
Thank you, Yan.
Allen Hovsepian
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