0

When I try to change the background color of a label, the whole label becomes transparent. Therefore the code works, but not in the way I actually need it to work. I need the text (ForeColor) to be a particular color, hence when the label is put over the pictureBox1, the text is only visible.

label1.Parent = pictureBox1;
        label1.BackColor = Color.Transparent;
        this.label1.ForeColor = Color.FromArgb(18, 148, 229);

before inputting the code

after inputting the code

  • You need here to reset the label's location after setting the `Parent` property. See [this](https://stackoverflow.com/a/9387562/14171304) fix. Alternative, use a `Panel` which is a _container_ control. The `PictureBox` is not. – dr.null Jun 10 '21 at 00:29
  • 1
    You didn't adapt the Location, so the Label is no longer visible. Set it to (0,0) to test! As it now is nexte in the Pbox /or, for that matter when you next it in any other control) its Location is now relative to the new control. You can calculate the correct Location btw with the `PointToScreen` and `PointToClient` functions.. [Example](https://stackoverflow.com/questions/30066477/recover-previous-absolute-position-for-picturebox-when-parent-is-changed/30071783#30071783) – TaW Jun 10 '21 at 01:34

0 Answers0