views:

106

answers:

1

I use a transparent background for the PictureBox control.

But I also want to be able to paint with a %50 opacity blue FillRectangle.

How to do this?

+4  A: 

.NET WinForm controls themselves do not support transparency, but GDI+ does as far as general rendering goes. If you are rendering onto a PictureBox (or onto anything else) and want to render something with partial opacity, then create a color with an alpha value less then 255 (opaque) and use it to create a brush or pen.

For example:

Color c = Color.FromArgb(128, Color.Blue);
using (Brush b = new SolidBrush(c))
{
  e.Graphics.FillRectangle(b, 0, 0, 50, 50);
}
Michael McCloskey
Yeah the PictureBox is rather limited. You might have to start doing your own OnPaint event.
Jared Updike
Thanks it worked.
Joan Venge