I want to create more than 1 TextBox in my application.
My code bellow only creates one TextBox because I create a global object.
My code to do this:
private Label ctrLabel = new Label();
public void btnAddCharacter_Click(object sender, EventArgs e)
{
String LableName = "Lbl_";
ctrLabel.Name = LableName;
ctrLabel.Text = txtIDImg.Text;
panel2.Controls.Add(ctrLabel);
}
If put Label ctrLabel = new Label(); inside the event btnAddCharacter_Click it will be create multiple object.
But all control using ctrLabel will error because it doesn't know ctrLabel.
The problem is: in other control of Winform will be using and manipulation with this object.
So, I don't know when user click text 1 or text 2, etc.. to apply a change to the corresponding with event like: cbxFontSize_SelectedIndexChanged, cbxFont_TextChanged, etc .....
My code like this:
private void cbxFontSize_SelectedIndexChanged(object sender, EventArgs e)
{
ctrLabel.Font = new Font(ctrLabel.Font.FontFamily, Convert.ToInt32(cbxFontSize.SelectedItem),
ctrLabel.Font.Style);
}
private void cbxFont_TextChanged(object sender, EventArgs e)
{
ctrLabel.Font = new Font(cbxFont.Text, ctrLabel.Font.Size, ctrLabel.Font.Style);
}
and much other control will change a property of an object(TextBox).
