tags:

views:

21

answers:

2

Hello! i have a weird label problem . If i introduce something like the code below, even though i create a label with the same attributes but different location , it only displays the first. If i comment the "a" section and leave the details for the b label, the b label is displayed correctly . What is wrong? Regards, Alexandru Badescu

                a = new Label();
                a.Name = listaS.ElementAt(i).nrSucursala;
                a.Location = new Point(20,  3);
                a.Text = listaS.ElementAt(i).nrSucursala + "";
                this.panel1.Controls.Add(a);


                b = new Label();
                b.Name = listaS.ElementAt(i).nrSucursala;
                b.Location = new Point(20, 11);
                b.Text = listaS.ElementAt(i).nrSucursala + "";
                this.panel1.Controls.Add(b);
A: 

From what you provided as code snippet it is difficult to say what is wrong. Try narrowing down the problem. Start by the evident that should work and progressively enhance it with other code:

var a = new Label();
a.Name = "a name";
a.Location = new Point(20,  3);
a.Text = "a text";
this.panel1.Controls.Add(a);

var b = new Label();
b.Name = "b name";
b.Location = new Point(20, 11);
b.Text = "b text";
this.panel1.Controls.Add(b);

Notice how the a and b variables are locally declared.

Darin Dimitrov
i've introduced something like your code and now it displays only b :-?
Badescu Alexandru
my Label a and Label b are also declared locally
Badescu Alexandru
What happened when you put this code in a newly created empty winforms application containing a single panel?
Darin Dimitrov
the same thing ..
Badescu Alexandru
It was the size.. but i don't understand why it worked for a label and not for 2 when i runned the code..
Badescu Alexandru
A: 

It was the size.. but i don't understand why it worked for a label and not for 2 when i runned the code..

Badescu Alexandru