创建标签数组C#

时间:2013-10-09 03:02:31

标签: c# arrays labels

我知道C#中有很多关于标签数组的问题,但我的标签外观与如何创建标签数组有关。

以下是我的一些代码(忽略所有静态值):

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]);
            }

我在全局创建了rssFeeds标签,并在Form.Load()中使用for循环创建了所有标签,rssFeeds[i] = new Label();

然而,当我跑步并查看我的表格时,它看起来像这样:

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

而不是:

'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'
.
.
.

我在标签属性中弄乱了MaximumSize格式,但我可能做错了(在上面的代码中已注释掉)。我知道这应该有效,因为如果我将文本输出到消息框,它会显示整行文本。

我是否遗漏了一些愚蠢的东西,或者在创建我需要知道的标签数组后面还有更多?

2 个答案:

答案 0 :(得分:0)

设置rssFeeds[i].AutoSize = true;

答案 1 :(得分:0)

看起来你的所有标签都有相同的默认宽度,你没有定义,并且宽度不足以让文字适应。因此,您需要确保它们具有正确的高度和宽度,以适合您希望它们显示的信息。