2012-11-11 50 views
33

我試圖更新我的Windows Forms應用程序中的狀態條,但沒有顯示任何內容。這裏是我的代碼:如何在Windows窗體中更新StatusStrip

private void textBox1_TextChanged(object sender, EventArgs e) 
{ 
    lines = Regex.Split(textBox1.Text.Trim(), "\r\n"); 
    lineCount = lines.Count(); 
    statusStrip1.Text = "Lines: " + lineCount; 
    statusStrip1.Refresh(); 
} 

回答

45

enter image description here

您將需要添加一個ToolStripStatusLabelStatusStrip

然後設置標籤的文字(您需要做一個statusstrip.Refresh,因爲狀態標籤上沒有刷新)。

Text屬性對StatusStrip來自StatusStrip中繼承ToolStrip(其又繼承Control),但不具有視覺效果,由於ToolStrips的性質。它可能有點混亂。

例子:

private void textBox1_TextChanged(object sender, EventArgs e) 
{ 
    //... 
    lines = Regex.Split(textBox1.Text.Trim(), "\r\n"); 
    lineCount = lines.Count(); 

    //this label is added in visual editor using the default name 
    ToolStripStatusLabel1.Text = string.Format("Lines: {0}", lineCount); 
    StatusStrip1.Refresh(); 
} 
+0

Update'*** StatusStrip ***''多線程'需要** InvokeRequired **或_TPL Tasks_,*恕我直言*。 – Kiquenet

0

我遇到了類似的問題,在這裏我看到了StatusStrip控制,但父控件中顯然沒有ToolStripStatusLabel項目。沒有顯示ToolStripStatusLabel項目的初始文本(例如,「就緒」)。標籤項目的Spring被設置爲trueTextAlignTopLeft

問題通過設置解決StatusStrip控件的LayoutStyleFlowToolStripStatusLabel項目的OverflowNever。顯然,當父控件的佈局樣式設置爲Table時,標籤項目被隱藏。