Scrollbar on label

  • Thread starter Thread starter Darrell Blake
  • Start date Start date
D

Darrell Blake

I'm writing an IRC client to teach myself C# and have run into a small
problem. I'm using a label to display all the text and when the text gets to
the bottom of the label it doesn't automatically scroll down so you can't
see the new messages. I want to do one of two things if possible. Either get
the label to automatically scroll down or add a scroll bar. Preferably, I
would like to have both because then it would be possible to see previous
messages.

Does anyone know if these are possible and point me in the right direction?

Darrell
 
You might want to try playing around with AutoSize on the label placing
it inside of a scrollable container such as a panel, and setting the AutoScroll
property. I am envisioning some issues here with the label not just extending
vertically down, but also horizontally off the right side which might just cause
a problem.
 
Darell,

For your purpose, i would recommend you richTextBox (non-editable). It comes
with scrollbars both ways (Horz and Vert) and it has lot more functions to
take advantage of. You can even color the text.

Label is not a scrollable control, and adding a external scrollbar would be
nice, if you can simulate all the functionalities of scrollbar.
 
You might want to try playing around with AutoSize on the label placing
it inside of a scrollable container such as a panel, and setting the AutoScroll
property.

So that the label just resizes as the text goes down? It doesn't seem really
efficient to me. Maybe I've chosen the wrong tool to display the text. Is
there anything other than a label which would be more efficient?
I am envisioning some issues here with the label not just extending
vertically down, but also horizontally off the right side

At the moment the text wraps round so this might not be a problem.

Darrell
 
For your purpose, i would recommend you richTextBox (non-editable).

That's done the job. Brilliant. I just have one more question though. Is it
possible to get the box to automatically scroll down with the text. At the
moment you have to scroll down manually.

Darrell
 
richTextBox1.ScrollToCaret();

I've already tried that. It doesn't work. I think it's because there isn't a
caret in the text box. One because it's not editable anyway and two because
what's being entered into the box is the response from the IRC server. It's
not actually user entry.

Darrell
 
Try this

richTextBox1.Focus();
richTextBox1.SelectionStart = richTextBox1.Text.Length;
richTextBox1.ScrollToCaret();
 
It's ok I've solved it. Apparently the HideSelection property of the
RichTextBox has to be set to false.

Darrell
 
Darrell,

Dynamically Scrolling a textbox as content changes
and lines are appended.

Just use the TextBox.AppendText() method.
Will work.

//--------------------------------
this.vtLog.AppendText("\r\n" + s);
this.vtLog.Update();
//--------------------------------
 
Back
Top