views:

633

answers:

1

Hi! I have a RichTextBox in my C#-application. Both horizontal and vertical scrolling are enabled.

Current behavior: When I reach the last line of visible text area, horisontal scrolling comes to place. But scrolling is being made by pixels, not by line. So I can't see the text I'm typing becase the line itself is partly (or completely) invisible until I do vertical scrolling with arrow button or dragging vertical scrollbar.

Expected behavior: I would like to have RichTextBox scrolling similar to scrolling in Notepad. In Notepad, I always see the line I'm typing in. It is really smooth line-based scrolling.

Any idea? Some implicit settings in RichTextBox? Anything else? Thanks,

+1  A: 

Adding event handler to the TextChanged event, and programmatically scrolling down Check out : this post at bytes.com

RA
Alexey, thanks for the answer. Hmm, seems I didn't get an idea. In MSDN: This event supports the .NET Framework infrastructure and is not intended to be used directly from your code.Could you please give me some clue?
Racoon
Alexey, I copied-pasted the example from bytes.com and ran it successfully. But it still has the same fault: when I reach the last line, I can only see half of it...
Racoon
as for the first comment - http://msdn.microsoft.com/en-us/library/system.windows.forms.control.textchanged.aspxas for the second - try to play with the arguments passed to the SendMessage method (max -richTextBox1.Height)...
RA
Alexey, thanks, I'll try to play with it. Btw, it's very strange there is no best practice solution for such a common task...
Racoon
Alexey, yes, it seems to work: SendMessage(richTextBox1.Handle, EM_SETSCROLLPOS, 0, new POINT(0, max - richTextBox1.Height + 50));But I'm still waiting for a simpler solution. Thanks, anyway!!
Racoon
Hey, I found an alternative solution. You can place a RichTextBox on a Panel and specify Padding. Here is the full story: http://msdn.microsoft.com/en-us/library/ms229728.aspxAnd it works! I tried it and was satisfined with the result. Two birds with one stone: good-looking padding and smooth scrolling. Hope it helps someone else.
Racoon