Witam,
koledzy i koleżanki mam pewien problem odnośnie dynamicznego tworzenia obiektów (button, label itd);
Chcę zrobić tak, że użytkownik będzie miał kilka opcji do wyboru i po wybraniu danej opcji będą się tworzyły odpowiednie obiekty np. 1 przycisk, 2 textBoxy i 4 labele.
Mam funkcję, która tworzy te komponenty i teraz chcę się do nich odnieść w innej funkcji, niestety nic się nie dzieje, kompilator nie zwraca błędu ale ewidentnie jest coś nie tak.
tutaj funkcja tworząca obiekty:
public void CreateMacro01Layout()
{
System.Windows.Forms.TextBox textBox1 = new System.Windows.Forms.TextBox();
Controls.Add(textBox1);
textBox1.Location = new Point(10, 50);
textBox1.Multiline = true;
textBox1.Size = new Size(80, 200);
System.Windows.Forms.TextBox textBox2 = new System.Windows.Forms.TextBox();
Controls.Add(textBox2);
textBox2.Location = new Point(95, 50);
textBox2.Multiline = true;
textBox2.Size = new Size(80, 200);
System.Windows.Forms.Label Label1 = new System.Windows.Forms.Label();
Controls.Add(Label1);
Label1.Text = "Numer artykułu";
Label1.Location = new Point(10, 35);
Label1.Size = new Size(80, 17);
System.Windows.Forms.Label Label2 = new System.Windows.Forms.Label();
Controls.Add(Label2);
Label2.Text = "EAN";
Label2.Location = new Point(95, 35);
Label2.Size = new Size(80, 17);
System.Windows.Forms.Label Label3 = new System.Windows.Forms.Label();
Controls.Add(Label3);
Label3.Text = "Wierszy: ";
Label3.Location = new Point(10, 255);
Label3.Size = new Size(80, 17);
System.Windows.Forms.Label Label4 = new System.Windows.Forms.Label();
Controls.Add(Label4);
Label4.Text = "Wierszy: ";
Label4.Location = new Point(95, 255);
Label4.Size = new Size(80, 17);
System.Windows.Forms.Button Button1 = new System.Windows.Forms.Button();
Controls.Add(button1);
button1.Text = "Uruchom";
button1.Location = new Point(180, 50);
button1.Size = new Size(60, 25);
}
obiekty się tworzą i teraz chcę zrobić taką prostą rzecz jak np. zmianę parametru text wcześniej stworzonego Label3 za pomocą stworzonego Button1
private void button1_Click(object sender, EventArgs e)
{
Label3.Text = "test";
}
tak jak wcześniej pisałem, błędów nie wyrzuca kompilator ale nie dzieje się nic po przyciśnięciu Button1.
Czuję, że coś źle deklaruje ...ktoś pomoże?