Stop RichTextBox from scrolling while Append()

A

alexia

Hi All,

This issue troubles me for a long time.
I have a RichTextBox which is being updated using Append() method.

My problem is that I want the RichTextBox to be updated and prevent it
from being scrolled at the same time if the user is clicking the
control.

When the user clicks the control the caret position is changed which
is suppose to be, but if Append happens, the caret is being moved to
the end of the control which causes the control to scroll.

Is there a way to cause the control to be updated with the new text
and prevent it from being scrolled down?

Thanks for the help.
 
F

Family Tree Mike

alexia said:
Hi All,

This issue troubles me for a long time.
I have a RichTextBox which is being updated using Append() method.

My problem is that I want the RichTextBox to be updated and prevent it
from being scrolled at the same time if the user is clicking the
control.

When the user clicks the control the caret position is changed which
is suppose to be, but if Append happens, the caret is being moved to
the end of the control which causes the control to scroll.

Is there a way to cause the control to be updated with the new text
and prevent it from being scrolled down?

Thanks for the help.

(It looks like this didn't go through the first time. Apologies if this
is a duplicate post.)

Use something like the following when updating your RichTextBox:

int pos = richTextBox1.SelectionStart;
richTextBox1.AppendText("Here is more...\n");
richTextBox1.SelectionStart = pos;
 
A

alexia

(It looks like this didn't go through the first time.  Apologies if this
is a duplicate post.)

Use something like the following when updating your RichTextBox:

int pos = richTextBox1.SelectionStart;
richTextBox1.AppendText("Here is more...\n");
richTextBox1.SelectionStart = pos;

Hello Mike,

Thank you for your reply.
I think I should have been more clear. Basically I want to disable the
Autoscroll. Your suggestion will not disable it.

The preoblem is that while the autoscroll is disabled I still want to
update the control and give the user an option to copy data from the
control.
 
F

Family Tree Mike

alexia said:
Hello Mike,

Thank you for your reply.
I think I should have been more clear. Basically I want to disable the
Autoscroll. Your suggestion will not disable it.

The preoblem is that while the autoscroll is disabled I still want to
update the control and give the user an option to copy data from the
control.

Here is a small change to keep the richtextbox selection the same while
updating it. I have to admit though, I don't understand the roll of the
autoscroll being disabled for what you want to accomplish, as the rtb
does not scroll while running this for me. I'm updating the rtb in a
timer event, while selecting and copying.

int pos = richTextBox1.SelectionStart;
int len = richTextBox1.SelectionLength;
richTextBox1.AppendText("Here is more...\n");
richTextBox1.SelectionStart = pos;
richTextBox1.SelectionLength = len;
 
A

alexia

Here is a small change to keep the richtextbox selection the same while
updating it.  I have to admit though, I don't understand the roll of the
  autoscroll being disabled for what you want to accomplish, as the rtb
does not scroll while running this for me.  I'm updating the rtb in a
timer event, while selecting and copying.

             int pos = richTextBox1.SelectionStart;
             int len = richTextBox1.SelectionLength;
             richTextBox1.AppendText("Here is more...\n");
             richTextBox1.SelectionStart = pos;
             richTextBox1.SelectionLength = len;

Hi Mike,

It doesn't work for me.
The autocontrol is not disabled.
 
A

alexia

Here is a small change to keep the richtextbox selection the same while
updating it.  I have to admit though, I don't understand the roll of the
  autoscroll being disabled for what you want to accomplish, as the rtb
does not scroll while running this for me.  I'm updating the rtb in a
timer event, while selecting and copying.

             int pos = richTextBox1.SelectionStart;
             int len = richTextBox1.SelectionLength;
             richTextBox1.AppendText("Here is more...\n");
             richTextBox1.SelectionStart = pos;
             richTextBox1.SelectionLength = len;

Hello Mike,

I want to make a control which behaves like the VS output control. You
can see that when you build a project/solution, the output window is
being updated. If you click the control, the output window is still
being updated,
but the caret is fixed on the same point the user clicked (scroll bars
are being updated). If user clicks the right mouse button the mouse
menu is displayed.
The user can also select text while this is happening during update of
the control...

I am trying to achieve behavior like that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top