0

我知道这里有很多关于 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了标签属性中的格式,但我可能做错了(在上面的代码中注释掉了)。我知道这应该可行,因为如果我将文本输出到消息框,它会显示整行文本。

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

4

2 回答 2

0

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

于 2013-10-09T03:14:37.320 回答
0

rssFeeds[i].AutoSize = true;

于 2013-10-09T03:11:52.690 回答