C# – Compact Framework: Fill Rectangle with solidbrush problem

ccompact-framework

In my mobile project, I want to fill a rectangle with semi transparent color. Through documents, I learn that I can create solid brush with color.fromargb(). But the problem is that I can just pass three parameter in the color.fromargb(Red, Green, Blue) instead of 4 params (alpha, red, green, blue). So how can I fix it? I'm working on compact framework 2.0. Thanks in advance.

Best Answer

The compact framework supports an overload taking just one Int32 parameter representing a 32-bit ARGB value. From that article:

The byte-ordering of the 32-bit ARGB value is AARRGGBB.

So if you know your R, G and B values as bytes, you should be able to create the value you want from that. Something like:

var argb = (Int32)(128 | r << 16 | g << 8 | b);
var color = Color.FromArgb(argb);

... and as per @Andrew Cash's comment below, you could left shift an alpha value by 24 if you want to adjust the transparency.

That code's untested, but you get the idea.

Related Topic