adding controls programmatically on winfform

J

jj

i try to add a group of linklabel to winform as following, but when running
it, i can only see one linklabel added (the first one). Could anyone help
me to solve it and tell me why?

thanks
jj
---------------------------------------------------
LinkLabel[] lnkCase = new LinkLabel[caseCount];

for (int i = 0; i < caseCount; i++)
{
lnkCase = new LinkLabel();
lnkCase.Text = dirs.Name;
lnkCase.Name = dirs.Name;
lnkCase.Location = new System.Drawing.Point(100 + i * 2, 80 + i *
2);
lnkCase.Size = new System.Drawing.Size(272, 23);
lnkCase.LinkClicked += new
System.Windows.Forms.LinkLabelLinkClickedEventHandler
(lnkCase_LinkClicked);
this.Controls.Add(lnkCase);
}

-----------------------------------------
 
T

timtos

Replace the corresponding line with
lnkCase.Location = new System.Drawing.Point(100, i*25);

Beside:
Do you really want to change the x-coordinate?
If the space between the linklabels is too big you also have to reduce the size
with the Size property...

Hope this helps,
timtos.
 
J

jj

it works. thank you very much.

could you also tell me why? what's the difference between (100, 80 + i*25)
and (100, 80 + i * 2)? one works while the other does not.


timtos said:
Replace the corresponding line with
lnkCase.Location = new System.Drawing.Point(100, i*25);

Beside:
Do you really want to change the x-coordinate?
If the space between the linklabels is too big you also have to reduce
the size with the Size property...

Hope this helps,
timtos.

jj said:
i try to add a group of linklabel to winform as following, but when
running it, i can only see one linklabel added (the first one). Could
anyone help me to solve it and tell me why?

thanks
jj
---------------------------------------------------
LinkLabel[] lnkCase = new LinkLabel[caseCount];

for (int i = 0; i < caseCount; i++)
{
lnkCase = new LinkLabel();
lnkCase.Text = dirs.Name;
lnkCase.Name = dirs.Name;
lnkCase.Location = new System.Drawing.Point(100 + i * 2, 80 + i *
2);
lnkCase.Size = new System.Drawing.Size(272, 23);
lnkCase.LinkClicked += new
System.Windows.Forms.LinkLabelLinkClickedEventHandler
(lnkCase_LinkClicked);
this.Controls.Add(lnkCase);
}
 
T

timtos

Have you tried smaller values between 2 and 25?
Take 10 or 15 for example. Your controls are overlapping and due to that only the top-most is visible.

The control´s height is not only the height of the text! You have to include the margin in your calculations.
That´s the reason I was talking about resizing your controls! You can reduce the height of the linklabels
to the height of the text. This way you can put them closer together...

Greetings,
timtos.

jj said:
it works. thank you very much.

could you also tell me why? what's the difference between (100, 80 + i*25)
and (100, 80 + i * 2)? one works while the other does not.


timtos said:
Replace the corresponding line with
lnkCase.Location = new System.Drawing.Point(100, i*25);

Beside:
Do you really want to change the x-coordinate?
If the space between the linklabels is too big you also have to reduce
the size with the Size property...

Hope this helps,
timtos.

jj said:
i try to add a group of linklabel to winform as following, but when
running it, i can only see one linklabel added (the first one). Could
anyone help me to solve it and tell me why?

thanks
jj
---------------------------------------------------
LinkLabel[] lnkCase = new LinkLabel[caseCount];

for (int i = 0; i < caseCount; i++)
{
lnkCase = new LinkLabel();
lnkCase.Text = dirs.Name;
lnkCase.Name = dirs.Name;
lnkCase.Location = new System.Drawing.Point(100 + i * 2, 80 + i *
2);
lnkCase.Size = new System.Drawing.Size(272, 23);
lnkCase.LinkClicked += new
System.Windows.Forms.LinkLabelLinkClickedEventHandler
(lnkCase_LinkClicked);
this.Controls.Add(lnkCase);
}

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top