0

how to ransparent background color label over button dynamic in c#?

Label titre= new Label();

PictureBox btnimage = new PictureBox();

btnimage.Name = "img" + i;

btnimage.Location = new Point(19, 15);

btnimage.Size = new Size(170, 153);

btnimage.BackgroundImageLayout = ImageLayout.Stretch;

// type annonces

titre.Name = "name" + i;

titre.Text = systeme.Annonces[i].name.ToString();

titre.ForeColor = Color.Black;

titre.TextAlign = ContentAlignment.MiddleCenter;

titre.Font = new Font("Tahoma", 9, FontStyle.Bold);

titre.Location = new Point(23, 125);
ADyson
  • 57,178
  • 14
  • 51
  • 63
nure
  • 19
  • 2
  • firstly can we ask _why_ you want to do this? Are you trying to make the box unclickable, or change its colour, or add text to it, or something? Because there are far better ways to do that. – ADyson Nov 08 '19 at 15:22
  • 1
    basically, this could work. pay attention to zorder. I think pictureboxes are even containers for child controls, so you could add the label to it. but would you not rather paint the text of the label into the picture box instead? – Cee McSharpface Nov 08 '19 at 15:22
  • I want to change its color – nure Nov 08 '19 at 15:26

1 Answers1

-1
titre.BackColor = System.Drawing.Color.Transparent;

Fair warning, transparency in WinForms is not fully supported.

Adam
  • 119
  • 6
  • It doesn't work with me because (titre) above (Picturebox) – nure Nov 08 '19 at 15:29
  • Please elaborate on how it doesn't work and your end goal. A screen grab will help. – Adam Nov 08 '19 at 15:32
  • look at the picture here https://i.stack.imgur.com/jneya.png – nure Nov 08 '19 at 15:40
  • Make sure you are adding the label to the picture box's controls, not the form's controls. Based on the picture and the info provided, it looks like the form is the label's parent. – Adam Nov 08 '19 at 16:00
  • Why the downvote? This achieved the desired result in my testing. – Adam Nov 08 '19 at 17:41