Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

RichTextBox to scroll

weiccoweicco Member Posts: 950
Hi,

I'm writing IRC client with C# :)

I create RichTextBox-control for every channel window where all channel messages are written. Now of course text box is too small to hold every line of bulls**t people tend to write in IRC so I need to scroll text box somehow. This is a snippet of the code I'm working on:

[code]
// Finds the right channel window and control
RichTextBox box = FindChannelWindow(channelName).FindOutputBox();

box.Text += channelMessage + "
";
[/code]

Then I have event-handler:

[code]
private void richTextBox1_TextChanged(object sender, System.EventArgs e)
{
RichTextBox box = sender as RichTextBox;
// Logging stuff
if (Settings.Logging) Logger.Write(ParseLastLine(box));
// Here I would like to scroll down the control
if (Box.Lines.Length > MaxLinesPerView)
{
// ???
}
}
[/code]

I found that ScrollToCaret would scroll control where caret is currently but I don't like to se focus to text box, I want to keep focus where user writes all channel messages. So is there any way to scroll down the text box or do I have to hassle with focus and ScrollToCaret?

Comments

  • athomasathomas Member Posts: 228
    Hi,

    you got 2 options. The first is, implementing a separate Scrollbar Control or set the RTB Scrollable property in the property box.

    Note when implementing a Scrollbar, which is not difficult, you need to dock that scrollbar on the side you want to put the scrollbar otherwise the scrollbar will not rezise with the window.

    Cheers.
    Alex

    : Hi,
    :
    : I'm writing IRC client with C# :)
    :
    : I create RichTextBox-control for every channel window where all channel messages are written. Now of course text box is too small to hold every line of bulls**t people tend to write in IRC so I need to scroll text box somehow. This is a snippet of the code I'm working on:
    :
    : [code]
    : // Finds the right channel window and control
    : RichTextBox box = FindChannelWindow(channelName).FindOutputBox();
    :
    : box.Text += channelMessage + "
    ";
    : [/code]
    :
    : Then I have event-handler:
    :
    : [code]
    : private void richTextBox1_TextChanged(object sender, System.EventArgs e)
    : {
    : RichTextBox box = sender as RichTextBox;
    : // Logging stuff
    : if (Settings.Logging) Logger.Write(ParseLastLine(box));
    : // Here I would like to scroll down the control
    : if (Box.Lines.Length > MaxLinesPerView)
    : {
    : // ???
    : }
    : }
    : [/code]
    :
    : I found that ScrollToCaret would scroll control where caret is currently but I don't like to se focus to text box, I want to keep focus where user writes all channel messages. So is there any way to scroll down the text box or do I have to hassle with focus and ScrollToCaret?
    :

Sign In or Register to comment.