As you know it is possible in WPF. But I have a project in Windows Forms but I don't want to struggle to move project into WPF. So is it possible in Windows Forms? (Unlike asked in another question, I don't ask transparency of a panel. I am asking "If I would use a background image", can I make it half transparent.)
You need to try two things: set the BackColor to Transparent and convert the image to something that has opacity.
From Change Opacity of Image in C#:
public Image SetImageOpacity(Image image, float opacity) {
Bitmap bmp = new Bitmap(image.Width, image.Height);
using (Graphics g = Graphics.FromImage(bmp)) {
ColorMatrix matrix = new ColorMatrix();
matrix.Matrix33 = opacity;
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);
g.DrawImage(image, new Rectangle(0, 0, bmp.Width, bmp.Height),
0, 0, image.Width, image.Height,
GraphicsUnit.Pixel, attributes);
}
return bmp;
}
Then you panel properties would look like this:
panel1.BackColor = Color.Transparent;
panel1.BackgroundImage = SetImageOpacity(backImage, 0.25F);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With