Question

I know there are a lot questions about array of labels in C# here, but mine has to do with the look of the labels not so much how to create an array of labels.

Here is some of my code (ignore all the static values):

for (int i = 0; i < 10; i++)
            {
                if (i % 2 == 0)
                {
                    newsTitle = GetTagData(rootRss, "title", i + 2);
                    rssFeeds[i].Location = new Point(xPt, yPt);
                    rssFeeds[i].Font = new Font(rssFeeds[i].Font, FontStyle.Bold);
                    rssFeeds[i].Text = "\tTEST" + i + newsTitle;
                }
                else
                {
                    newsDesc = GetTagData(rootRss, "description", i + 1);
                    rssFeeds[i].Location = new Point(xPt, yPt + 25);
                    rssFeeds[i].Font = new Font(rssFeeds[i].Font, FontStyle.Regular);
                    rssFeeds[i].Text = newsDesc;
                    yPt += 75;
                }
                //rssFeeds[i].MaximumSize = new Size(400, 400);
                this.Controls.Add(rssFeeds[i]);
            }

I have created the rssFeeds label globally and in the Form.Load() created all the labels using a for loop, rssFeeds[i] = new Label();

However when I run and look at my form it looks like this:

'This is the f'
'This is the s'
'This is the t'
'This is the f'
.
.
.

Rather than this:

'This is the first line of data from the news headline today'
'This is the second line of data from the news headline today'
'This is the thrid line of data from the news headline today'
'This is the fourth line of data from the news headline today'
.
.
.

I have messed around with the MaximumSize format in the label properties, but I may have been doing it wrong (commented out in the above code). I know this should work because if I output the text to a messagebox it displays the entire line of text.

Am I missing something stupid or is there more behind creating label arrays that I need to know?

Was it helpful?

Solution

Set rssFeeds[i].AutoSize = true;

OTHER TIPS

It looks like all of your labels have the same default width which you're not defining, and are not wide enough for the text to fit into. So you need to make sure they have the correct height and width for them to fit the information you want them to display.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top