Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

SetSysColors (user32)
 
.
Summary

C# Signature:

[DllImport("user32.dll")]
static extern bool SetSysColors(int cElements, int [] lpaElements,
   uint [] lpaRgbValues);

User-Defined Types:

None.

Notes:

This function changes the color for the current session only. To persist the change, you must update the registry keys at HKEY_CURRENT_USER\Control Panel\Colors

Tips & Tricks:

Please add some!

Sample Code:

[DllImport("user32.dll", SetLastError=true)]
public static extern bool SetSysColors(int cElements, int [] lpaElements, int [] lpaRgbValues);
public const int COLOR_DESKTOP = 1;

//example color
System.Drawing.Color sampleColor = System.Drawing.Color.Lime;

//array of elements to change
int[] elements = {COLOR_DESKTOP};

//array of corresponding colors
int[] colors = {System.Drawing.ColorTranslator.ToWin32(sampleColor)};

//set the desktop color using p/invoke
SetSysColors(elements.Length, elements, colors);

//save value in registry so that it will persist
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Control Panel\\Colors", true);
key.SetValue(@"Background", string.Format("{0} {1} {2}", sampleColor.R, sampleColor.G, sampleColor.B));

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions