Fix only the width of the Label and use a scrollbar for height in WinForm

Here, I am going to demonstrate quick fix of these two problems.

Fixed Width:

Keep AutoSize  property of the Label to true.
Set the MaximumSize property to, say, (100,0). So that its horizontal growth has been capped to 100 but there will be no restriction on the vertical growth.

Add Scrollbar to Windows Label:

Place the Label inside a Panel and set its AutoScroll property to true.
OR,
you can also use a read-only, multi-line textbox to accomplish the same task.
Advertisements

Automatically Scroll to the Bottom of a Multiline TextBox

The requirement is pretty simple. There’s a multiline textbox which is getting updated at a fixed time interval. So I wan’t the focus inside the textbox (or you can say the cursor position) should always be on the last line. To do that write the following code in the TextChanged event of your textbox


private void textBox1_TextChanged(object sender, EventArgs e)
{
  textBox1.SelectionStart = textBox1.Text.Length;
  textBox1.ScrollToCaret();
}