How do draw an image in a disabled state?

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

Hi everyone

Does anyone know how to draw an image in a disabled state on the compact
framework?
I have created a dropdown button akin to the forward and back button in IE
but I'm stuck when it comes to putting the button in a disabled state.

Any help would be much appreciated.
Thanks in advance
Dan
 
The Control.Enabled property (=false) should do it... or just create a copy
of your image replacing all white with the light grey and every other color
with dark grey.

Cheers
Daniel
 
Arh I did wonder if the easiest way would just be to have a copy of the
image, I know how to do it in the full framework for changing it on the fly
on just one image.

Dan
 
So it will get like disabled, convert a certain Image as grayscale by
computing Y value (is the grayscale component in YIQ) by this formula:

Y = 0.299 * R + 0.587 * G + 0.114 * B

and then use Y value as R, G, B parameters for a color. See the code
snippet bellow, "dst" variable will contain grayscale image from
"source" bitmap:

Bitmap dst = new Bitmap(source.Width, source.Height);

for(int y=0; y < dst.Height;y++)
{
for(int x=0; x < dst.Width; x++)
{
Color c = source.GetPixel(x, y);
// alternatively Y = (77 * c.R + 150 * c.G + 29 * c.B) >> 8
int Y = (int)(c.R * 0.299 + c.G * 0.587 + c.B * 0.114);
dst.SetPixel(x, y, Color.FromArgb(Y, Y, Y));
}
}


Hope this help,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
Back
Top