Zayko in the Net

Personal blog of Vitaly Zayko


Inverting colors (C#)

Sometimes, when you change, for example, background color of an object dynamically, you should dynamically change foreground color as well to keep a text readable. Here is very simple way to do it:

public Color InvertColor(Color color){
    return Color.FromArgb(color.ToArgb() ^ 0xFFFFFF);