I create a program in this can add label and picture box.
All control must is children of a panel.
I use code like this:
panel2.Controls.Add(picturebox1);
panel2.Controls.Add(label1);
Yup, the problem is I want label over picture box.
I was set with code:
label1.Parent = pictureBox1;
label1.BackColor = Color.Transparent;
Update:
Because control only creates when I want to create by button_event. Like, create picture box, create label text. This is not was created before I want to use them.
My code to create this control:
public PictureBox ctrl = new PictureBox();
public void btnAddLogo_Click(object sender, EventArgs e)
{
Random rnd = new Random();
int randNumber = rnd.Next(1, 1000);
String picName = "Pic_" + randNumber;
ctrl.Location = new Point(200, 170);
ctrl.Size = new System.Drawing.Size(100, 60);
ctrl.Name = picName;
ctrl.BackgroundImageLayout = ImageLayout.Zoom;
ctrl.Font = new System.Drawing.Font("NativePrinterFontA", 10F, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, ((byte) (0)));
ctrl.BackColor = Color.Chocolate;
panel2.Controls.Add(ctrl);
}
private Label ctrLabel = new Label();
public void btnAddCharacter_Click(object sender, EventArgs e)
{
Random rnd = new Random();
int randNumber = rnd.Next(1, 1000);
String LableName = "Lbl_" + randNumber;
ctrLabel.Name = LableName;
ctrLabel.AutoSize = true;
ctrLabel.Text = txtIDImg.Text;
ctrLabel.BackColor = Color.Transparent;
panel2.Controls.Add(ctrLabel);
}
But result shows like: