Over a million developers have joined DZone.

.Net → C# – Get Windows Mobile Theme Color

DZone 's Guide to

.Net → C# – Get Windows Mobile Theme Color

· Mobile Zone ·
Free Resource

I recently had a business requirement to color the background of a TextBox in Windows Mobile to a specific color.  After completing the tasks, I noticed that the color that was chosen(blue) didn’t look right on devices that used a different theme like red or green.  So I decided to figure out how to set the background color to match the theme color.

The theme system colors are located in the registry entry HKLM\System\GWE\SysColor.  This registry entry is a BLOB that contains 29 DWORD values that correspond to the different colors of the theme.

For my application, I decided to use the color of the title bar of active windows.  This color is normally the dominate color of the theme.  This color is the third DWORD value in the registry entry.

Each DWORD value in the registry entry is a 4 byte HEX value that corresponds to a specific color.  The first byte is the RED value, second value is the GREEN value, third value is the BLUE value, and the fourth value is always 0.

For this code, I used the OpenNetCF framework to get the registry values.

/// <summary>
/// Gets the theme color
/// </summary>
/// <returns> Returns a Color or null</returns>
public Color? GetThemeColor()
         // gets the registry key
         RegistryKey keyColor = Registry.LocalMachine.OpenSubKey(@"System\GWE");
         // keyColor will be null if registry key was not found
         if (keyColor == null)
             return null;
        byte[] data = (byte[])keyColor.GetValue("SysColor");
        if (data[8] != 0 && data[9] != 0 && data[10] != 0)
             // the third set of values is for the color of the
             //    title bar of an active window.
             int red = Convert.ToInt32(data[8]);
             int green = Convert.ToInt32(data[9]);
             int blue = Convert.ToInt32(data[10]);
             return Color.FromArgb(red, green, blue);
        return null;
         return null;

Usage is pretty simple for the method…

Color? themeColor = GetThemeColor();
if(themeColor != null)
   txtComments.BackColor = themeColor;






Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}