0

I'm working on a Winforms (C#) benchmark project and am trying to build a Spongebob-themed GUI. When someone clicks on the "Start Benchmark" button, it will redirect the user to a page containing a GIF with Patrick smashing a computer, together with an "Exit" button and with a "Running benchmark..." label attached.

I'm using a texture for the "Exit" button, which doesn't really have a rectangular form. So, I'm using the BackColor = Transparent property to avoid having "random white corners".

I'm also using the pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; in the Form.Load() method, because I realized PictureBox doesn't have any property that lets you stretch an image all over the control.

This is how the form looks like (in VS): enter image description here

The GIF should stretch out on the whole form (and it does that without any problems). The only problem is this:

enter image description here

Exit and Running benchmark... controls have a background color, and I noticed this happens only when putting them on the PictureBox. All three controls (Button, Label and PictureBox) have the BackColor=Transparent property set, but this one doesn't seem to do anything in my case.

My question is: how can I make the background of the button and the label transparent? (programmatically or not)

Mario Mateaș
  • 638
  • 7
  • 25
  • 3
    You can set the Label's `Parent` to your PictureBox, reposition and anchor it, then call its `Refresh()` method. You can probably do the same with the Button, but since it's a Custom Control, I cannot say for sure, just test it. The background Color of the PictureBox doesn't need to be `Color.Transparent` – Jimi Apr 12 '22 at 14:35
  • @Jimi Seemed to work. Please, provide this as an answer so I can choose it as being the right one. Thank you so much! – Mario Mateaș Apr 12 '22 at 14:52
  • 1
    Many duplicates, e.g., [Transparent control over PictureBox](https://stackoverflow.com/q/9387267/7444103). Do you agree? – Jimi Apr 12 '22 at 15:09
  • @Jimi Yeah, seems to be similar to what I asked... – Mario Mateaș Apr 12 '22 at 16:23

0 Answers0