469,592 Members | 2,026 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

RichTextBox ; Autoscrolling after selection change ?

Hi,

I'm working on a RichTextBox with some "in-program" style-features
(e.g. *no way* becomes bold : like MS Word does). Got everything
working fine, flickerfree and reasonable fast, but in order to set the
style of some part of the text I use the "Selection" method (in the
case of *text* the

richTextBox1.SelectionFont.Bold = true

No problem so far, unless there are scrollbars involved. Somehow, when
I type into the RichTextBox (and after the styles are applied) the
current selection position becomes the top row; unless there is no
"scrollbar left" to scroll down to.

I've added a small sample of the code below

Expand|Select|Wrap|Line Numbers
  1.  
  2. Cursor = Cursors.WaitCursor;
  3. int origSelStart = richTextBox1.SelectionStart;
  4. int origSelLength = richTextBox1.SelectionLength;
  5.  
  6. // Freeze control
  7. SendMessage(richTextBox1.Handle, 11, 0, 0);
  8.  
  9. if (SingleLine)
  10. {
  11. // Only do the appropriate line
  12. ApplyLineStyle(Line);
  13. }
  14. else
  15. {
  16. // Apply style on all lines
  17. for (int i = 0; i < richTextBox1.Lines.GetLength(0); i++)
  18. {
  19. ApplyLineStyle(i, false);
  20. }
  21. }
  22.  
  23. // Unfreeze control
  24. SendMessage(richTextBox1.Handle, 11, 1, 0);
  25. richTextBox1.Refresh();
  26.  
  27. // Turn original selection-state back
  28. richTextBox1.SelectionStart = origSelStart;
  29. richTextBox1.SelectionLength = origSelLength;
  30.  
  31. SingleLine = false;
  32. Cursor = Cursors.Default;
  33.  
  34.  
What am I missing, is there a property or method I could use?

TIA,
Leon
Apr 11 '06 #1
1 2909
On Tue, 11 Apr 2006 13:54:17 +0200, Leon Friesema
<le***********@frostbits.nl> wrote:
Hi,

I'm working on a RichTextBox with some "in-program" style-features
(e.g. *no way* becomes bold : like MS Word does). Got everything
working fine, flickerfree and reasonable fast, but in order to set the
style of some part of the text I use the "Selection" method (in the
case of *text* the

richTextBox1.SelectionFont.Bold = true

No problem so far, unless there are scrollbars involved. Somehow, when
I type into the RichTextBox (and after the styles are applied) the
current selection position becomes the top row; unless there is no
"scrollbar left" to scroll down to.

I've added a small sample of the code below

[code]

What am I missing, is there a property or method I could use?

TIA,
Leon


Sorry, found the problem: not using SelectionStart and SelectionLength
when selecting (using the Select Method) does help

Thx anyway,
Leon
Apr 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Michael A. Covington | last post: by
2 posts views Thread by Hariharan S | last post: by
1 post views Thread by John Baro | last post: by
2 posts views Thread by Clark Stevens | last post: by
1 post views Thread by Vivien Parlat | last post: by
2 posts views Thread by =?Utf-8?B?TWFyayBDb2xsYXJk?= | last post: by
4 posts views Thread by =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.