✅ Cannot make an label background color transparent (On a picture box)
I tried and searched a lot of way of making a background color label transparent. (btw im making it programmatically)
c#
pictureBox.Image = Image.FromFile("your_image_path.jpg"); // if you don't have an image you don't need this
Label textLabel = new Label();
textLabel.Text = "TEST";
textLabel.BorderStyle = BorderStyle.None;
textLabel.ForeColor = Color.Black;
textLabel.BackColor = Color.Transparent;
textLabel.Font = new Font("Arial", 12, FontStyle.Regular);
textLabel.Location = new Point(410, 40);
textLabel.Size = new Size(200, 100);
textLabel.TextAlign = ContentAlignment.MiddleCenter;
pictureBox.Controls.Add(textLabel); //adding the label to picturebox
mainForm.Controls.Add(pictureBox);c#
private void Form1_Load(object sender, EventArgs e)
{
// This ensures the form is hidden when it loads
this.Visible = false;
}c#
public Program()
{
#region FORM
this.Size = new Size(1100, 700);
this.TopMost = true;
this.StartPosition = FormStartPosition.CenterScreen;
this.FormBorderStyle = FormBorderStyle.None;
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));
this.Load += Program_Load; // Attach Load event handler
#endregion
}
private void Program_Load(object sender, EventArgs e)
{
// Set form's visibility to false when it loads
this.Visible = false;
}this.Loadthis.Shownthis.Shown += Program_Load;LoadShown Label textLabel = new Label();
textLabel.Text = "TEST";
textLabel.BorderStyle = BorderStyle.None;
textLabel.ForeColor = Color.Transparent;
//textLabel.Parent = pictureBox;
textLabel.FlatStyle = FlatStyle.Standard;
textLabel.BackColor = Color.Transparent;
textLabel.Font = new Font("Arial", 12, FontStyle.Regular);
textLabel.Location = new Point(410, 40);
textLabel.Size = new Size(200, 100);
textLabel.TextAlign = ContentAlignment.MiddleCenter;
mainForm.Controls.Add(textLabel);public Program()
{
#region FORM
this.Size = new Size(1100, 700);
this.TopMost = true;
this.StartPosition = FormStartPosition.CenterScreen;
this.FormBorderStyle = FormBorderStyle.None;
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));
this.Load += (sender, e) => this.Visible = false;
#endregion
}