Click here to Skip to main content
13,258,238 members (50,350 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 16 May 2007

Changing VS Code Region Coloring Using XML

, 16 May 2007
Rate this:
Please Sign up or sign in to vote.
This article shows how to change the color schemes of code regions in VS quickly by using XML.


Have you ever thought about converting your VS color settings into something like CSS and porting it into another Visual Studio IDE by only clicking a button? Here's how.


While I was composing programs, I wanted to change the color scheme of my IDE, yet since it takes a long time for me to recover the original one, I did not do that for its complexity. But I finally really couldn't stand my color scheme, and then I wrote this -- it enables me to switch my code region color themes quickly and does not require restarting Visual Studio.

Using the code

Here's the code, and follow the steps below to use this macro.

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics

Public Module Theme
    Public Sub LoadTheme()
        Dim path As String = _
          InputBox("please enter the theme file location", "load theme file")
        Dim file As New Xml.XmlDocument
        For Each item As Xml.XmlNode In file.ChildNodes(0).ChildNodes
            Dim i1 As ColorableItems = CType(DTE.Properties("FontsAndColors", _
               "TextEditor").Item("FontsAndColorsItems").Object, _
            i1.Background = UInteger.Parse(item.Attributes("background").Value)
            i1.Foreground = UInteger.Parse(item.Attributes("foreground").Value)
            If item.Attributes("bold").Value = "True" Then
                i1.Bold = True
                i1.Bold = False
            End If
    End Sub
    Public Sub DumpTheme()
        Dim path As String = _
          InputBox("please enter the export file location", "load theme file")
        Dim file As New Xml.XmlDocument
        For Each item As ColorableItems In CType(DTE.Properties("FontsAndColors", _
                "TextEditor").Item("FontsAndColorsItems").Object, FontsAndColorsItems)
            Dim i As Xml.XmlNode = file.CreateElement("item")
            i.Attributes(0).Value = item.Foreground
            i.Attributes(1).Value = item.Background
            i.Attributes(2).Value = item.Bold.ToString
            i.Attributes(3).Value = item.Name
    End Sub
End Module
  • Step 1: Open the Macros IDE [Tools->Macros->Macros IDE].
  • Step 2: In the MyMacros project in the Solution Explorer of the Macros IDE, right click, then select Add Module. Paste the code into it and the macro is ready to use by executing it in the Macro Explorer.

Context-menu items

Actually, you can add this macro as a button on a toolbar or a context-menu item. Just check out Tools->Customize->Macros and follow the on screen instructions.

IDE usage report

During my coding process, I discovered that the Macros IDE is actually very buggy. The Smart Indentation actually cannot handle classes well, it took too much time in loading the code I have just written. On top of that, the Macros IDE cannot load Windows Forms dialogs such as OpenFileDiaog. I jumped to this trick and it lengthened the time for me to finish the work.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Hong Kong Hong Kong
Rakusu is a student who has goodcommand of ASPNET, C++ and SQL. She helps manages her school's server and write programs for her school. She also help managing servers for a small computer company. Currently she is preparing for her exams and studies.

You may also be interested in...


Comments and Discussions

GeneralOne more humble opinion Pin
Member 433593319-Jul-09 0:56
memberMember 433593319-Jul-09 0:56 
GeneralCool Pin
Ziad Elmalki23-Jun-09 21:40
memberZiad Elmalki23-Jun-09 21:40 
GeneralVisual Studio 2005 Export/Import Settings Pin
SoniqueShock21-May-07 22:50
memberSoniqueShock21-May-07 22:50 
* On the VS2005 main menu, select 'Tools>Import and Export Settings...'
* From the 'Import and Export Settings Wizard' select 'Export selected environment settings' and click OK.
* You can now select which settings you want to export. To export the Fonts and Colors, check the tree node: 'All Settings>Options>Environment>Fonts and Colors'.
* Click next and specify a name for the export file.

This file can now be imported on another VS2005 instance using the same wizard.
Questionwhat about exporting your settings? Pin
nsimeonov21-May-07 21:04
membernsimeonov21-May-07 21:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171114.1 | Last Updated 16 May 2007
Article Copyright 2007 by Rakusu
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid