37

I am trying to update the status strip in my Windows Forms application, but nothing is being displayed. Here is my code:

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();
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Luke101
  • 63,072
  • 85
  • 231
  • 359

2 Answers2

52

enter image description here

You will need to add a ToolStripStatusLabel to the StatusStrip.

Then set the text of the label instead (you need to do a statusstrip.Refresh as there is no refresh on the status-label).

The Text property on the StatusStrip comes from the StatusStrip inherits ToolStrip (which in turn inherits Control), but has no visual effect due to the nature of ToolStrips. It can be a bit confusing.

Example:

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();
}
Community
  • 1
  • 1
0

I encountered a similar problem, where I see a StatusStrip control but apparently without ToolStripStatusLabel item within the parent control. Not even the initial text for the ToolStripStatusLabel item (e.g., "Ready") was displayed. The label item's Spring was set to true and TextAlign to TopLeft.

The problem was resolved by setting the StatusStrip control's LayoutStyle to Flow and the ToolStripStatusLabel item's Overflow to Never. Apparently the label item was hidden when the parent control's layout style was set to Table.

H Yoo
  • 1
  • 1