I am trying to write some text over my picturebox so I thought the easiest and best thing to do is draw label over it. This is what I did:
PB = new PictureBox();
PB.Image = Properties.Resources.Image;
PB.BackColor = Color.Transparent;
PB.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
PB.Size = new System.Drawing.Size(120, 30);
PB.Location = new System.Drawing.Point(100, 100);
lblPB.Parent = PB;
lblPB.BackColor = Color.Transparent;
lblPB.Text = "Text";
Controls.AddRange(new System.Windows.Forms.Control[] { this.PB });
I get blank page with no PictureBoxes. What am I doing wrong?
While all these answers work, you should consider opting for a cleaner solution. You can instead use the picturebox’s
Paintevent:Edit To draw the text centered: