创建标签数组 C#

本文关键字:数组 标签 创建 | 更新日期: 2023-09-27 18:34:34

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

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

创建标签数组 C#

Set rssFeeds[i].AutoSize = true;

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