i don't want to waste your time with introductions, am just going to ask the question straight up.
am trying to make a dynamic form, where i can change what is inside of it through the parameters passed when the form is called, my problem occurs when i want to do something with the stuff i created outside of the creation method,
here is an extremely simplified example to hopefully better communicate the problem:
public partial class MyForm : Form
{
public MyForm()
{
InitializeComponent();
CreateLabels();
CreateButtons();
}
// creates and locates labels in the form
private void CreateLabels()
{
Label Lbl = new Label();
Lbl.Text = "help please"
Lbl.Name = "MainLabel";
Lbl.Location = new Point(this.Width / 2, 30);
this.Controls.Add(Lbl);
}
// creates and locates buttons in the form
private void CreateButtons()
{
Button Btn = new Button();
Btn.Name = "Mainbuttom";
Btn.Location = new Point(this.Width / 2, 100);
Btn.BackColor = Color.Red;
this.Controls.Add(Btn);
Btn.Click += new EventHandler(button_click);
}
// does something when the user presses the button
private void button_click(object sender, EventArgs e)
{
// do something with the labels created, e.g : save the text inside, change the text, etc.
}
}
ya, so i want to access the labels created somehow.
i wasted so much time on this i hope its not as simple as changing a parameter,
anyways, thanks for your time.