2013-10-09 76 views
0

我知道這裏有很多關於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格式周圍亂,但也可能是我做錯了(在上面的代碼中註釋掉)。我知道這應該起作用,因爲如果我將文本輸出到消息箱,它會顯示整行文本。

我是否錯過了某些愚蠢的東西,或者在創建標籤數組後面有更多我需要知道的東西?

+0

標籤的寬度小於字符串的大小。 –

回答

0

rssFeeds[i].AutoSize = true;

+0

謝謝,我認爲這是默認情況下我應該想到這一點。盯着代碼很長一段時間讓我很蠢。 – Bit10Bytes

0

它看起來像您的所有標籤中有哪些你沒有定義相同的默認寬度,並且不足夠寬以適應文本。因此,您需要確保它們具有正確的高度和寬度,以適合您希望它們顯示的信息。

+0

這兩個答案都是我一直在尋找的,我只是選擇了autosize,因爲我不知道我需要的標籤有多寬。謝謝。 – Bit10Bytes