簡體   English   中英

創建標簽數組C#

[英]Creating an Array of Labels C#

我知道這里有關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格式,但是我可能做錯了(在上面的代碼中作了注釋)。 我知道這應該可行,因為如果我將文本輸出到消息框,它將顯示整行文本。

我是否缺少一些愚蠢的東西,或者在創建我需要知道的標簽數組之后還有其他事情嗎?

設置rssFeeds[i].AutoSize = true;

似乎所有標簽都具有未定義的相同默認寬度,並且寬度不足以容納文本。 因此,您需要確保它們具有正確的高度和寬度,以適合您希望它們顯示的信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM