Click here to Skip to main content
11,929,675 members (58,525 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# Scrolling
I have a RichTextBox. But when you scroll (using scrollbar of the RTB and scrolling wheel on mouse) it scrolls 'smoothly'(in pixels), but I want it to scroll line by line. Is this possible?

Posted 27-Jan-12 8:35am
SAKryukov 27-Jan-12 14:47pm
Why?! What if your users want to scroll as it is now?
SAKryukov 27-Jan-12 14:50pm
What RichTextBox? Do you think there is only one type under this name? No!
You need to give us a fully-qualified name. Also, tag your UI library: WPF, Forms, something else.

However, in this very case I don't think this is relevant.
But! Some other expert might think this is important -- tag it!
LanFanNinja 28-Jan-12 0:05am
I totally agree with what SAKryukov is saying here. I have used applications with text areas that only scroll line by line and for some reason it really bothers the crap out of me.

This is however your application and if you feel you need/want this functionality then by all means go on and implement it. :)
ikkentim 28-Jan-12 5:18am
Do you still have the script for it? At least I wat to try in :)

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The problem is: in rich text, there is no such think as constant inter-line interval throughout the text. Even though scrolling by exactly N lines is theoretically possible (select a range in a last line and press Down N times), the performance of this operation could be prohibitively slow. (And don't take this example as the idea for implementation anyway: input simulation is a dirty trick, should never be used in decent UI development.)

Scrolling is very fast compared to any other navigation operation, and this is only possible because the scrolling is "geometrical", not "logical". You should not replace this important functionality with any other questionable "feature".

Even if you could introduce "alternative scrolling" using some additional control of some kind, don't expect the user appreciate it. My best advice is: leave it as is; keep it smooth. Smile | :)

If you really need to move line by line, maybe the rich text is not what you need, and you really need a list box, a list view or a grid control…

Sean A. Hanley 27-Jan-12 18:18pm
Assuming he means WPF, I know with some scrollable containers you can influence the smooth-scroll/line-by-line-scroll behavior by manipulating ScrollViewer.CanContentScroll but this only works when the list contents is virtualized and has some kind of discrete list of things to scroll (i.e. other WPF controls)... with text, well... I think SAKryukov is right, there ain't a good way, really.
SAKryukov 27-Jan-12 18:27pm
This is reasonable. Thank you for this comment, Sean.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 27 Jan 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100