C# How can I access to a dynamic created array of labels
- by Markus Betz
I created an array of labels on runtime. Now i have a problem to access these labels from other functions.
Dynamic creation:
private void Form1_Shown(object sender, EventArgs e)
{
Label[] Calendar_Weekday_Day = new Label[7];
for (int i = 0; i < 7; i++)
{
Calendar_Weekday_Day[i] = new Label();
Calendar_Weekday_Day[i].Location = new System.Drawing.Point(27 + (i * 137), 60);
Calendar_Weekday_Day[i].Size = new System.Drawing.Size(132, 14);
Calendar_Weekday_Day[i].Text = "Montag, 01.01.1970";
this.TabControl1.Controls.Add(Calendar_Weekday_Day[i]);
}
}
And the function where I want to access to the dynamic created array of labels:
private void display_weather_from_db(DateTime Weather_Startdate)
{
Calendar_Weekday_Day[0].Text = "Test1";
Calendar_Weekday_Day[1].Text = "Test2";
}
Error shown: Error 1 The name 'Calendar_Weekday_Day' does not exist in the current context Form1.cs 1523 25 Test
I tryed this, but didn't help :(
public partial class Form1 : Form
{
private Label[] Calendar_Weekday_Day;
}
Someone an idea?