0

I am building a project in C# right now that needs to draw some stuff (text, bitmaps, rectangle) on a semi-transparent picturebox. More precisely, it goes like this:

WinForm > Panel (with BG image) > Picturebox (80% BG opacity) > Graphics.Draw

The PictureBox works as a frame for the drawn stuff. It has a solid white BG, but I need to reduce its opacity to like 80-85%, so the panel's BG image is sligtly visible. I tried changing the alpha from the BG color, but when I draw my data on the picturebox, they are shown on a lower opacity.

Is there any way I can have 80% opacity on BG color, but 100% opacity on drawn stuff? Maybe overlaying the picturebox, with another picturebox. Changing the alpha per bit is a heavy task.

Efthymios
  • 253
  • 3
  • 10
  • I think you can't: https://stackoverflow.com/a/4464161/578411 – rene Jul 02 '17 at 09:09
  • This would be much much easier to do with WPF rather than WinForms – PhonicUK Jul 02 '17 at 09:12
  • @PhonicUK I am bound to use WinForms for the time being, because I lack the WPF knowledge. Also the project is scheduled to be completed in a limited period of time, so I started it right away (no time to study WPF). If I get no feasible solution or workaround, maybe I'll leave the opacity as is. – Efthymios Jul 02 '17 at 09:18
  • 1
    PictureBox supports transparency well, all you have to do is pick the correct BackColor to get the intended effect. That should not be solid white, consider pictureBox1.BackColor = Color.FromArgb(80, Color.Black). – Hans Passant Jul 02 '17 at 09:19
  • @HansPassant Yeah, but I've already stated that if I use a custom alpha color, the drawn stuff will also have the same alpha. I need them to have 100% opacity. – Efthymios Jul 02 '17 at 09:30
  • 1
    Show the drawing code! It should work without a problem; BackColor, BackgroundImage, Image and paint drawing are all stacked but other than that independent - Of copurse _It has a solid white BG, but I need to reduce its opacity to like 80-85%_ this is contradictory! As Hans wrote use `pictureBox1.BackColor = Color.FromArgb(80, Color.White)` – TaW Jul 02 '17 at 09:36
  • 1
    It most certainly doesn't, you get the color that you draw with. And of course you would use one with an alpha of 255. The only possible mistake you could be making is not trying it. – Hans Passant Jul 02 '17 at 09:38
  • @TaW I meant to say I want a semi-transparent white background. Just so I can have a "white frame" for my information to be drawn. Allow me to try it once more and I'll report back with the code. – Efthymios Jul 02 '17 at 09:56
  • 1
    You were both correct! The BackColor works indepedently from the Image and Paint event. My problem was that I somehow left a line that was changing the BackColor to Color.White everytime I was painting the PictureBox. Now I just initiate the BackColor to Color.FromArgb(myOpacity * 255 / 100, Color.White) once and it works like a charm! Thank you! – Efthymios Jul 02 '17 at 10:06

0 Answers0