Click here to Skip to main content
14,328,470 members
Rate this:
Please Sign up or sign in to vote.
See more:
If you have RichTextBox scrollbars turned off (set to None) and are using a SendMessage() call from C# to user32.dll to scroll it, you don't get SCROLLINFO while the scrollbars are turned off. That means you have to keep a line counter and use SB_LINEUP and SB_LINEDOWN in the low 16 bits of Lparam as usual, but since the position you would place in the high 16 bits would ordinarily come from reading a SCROLLINFO using GetScrollInfo() and you don't have that to use even if you'd want to send SB_THUMBTRACK or SB_THUMBPOSITION, I don't think a zero for this value is out of place.

You can still manage OK with a line counter and just calling a scroll routine to LINEUP or LINEDOWN; and if you need to scroll a distance you can set richTextBox.Visible=false beforehand. The text region will flash, but it still isn't too bad if you're jumping a distance of, say 2500 lines; and you can always sample the background color of an .rtf file being displayed and set the background color of the panel the RichTextBox is on to that color. All in all, although there isn't really any direct way to programmatically scroll one of these things, it can be done fairly consistently even with single-line scrolling.

But what happens when you have, say, a bitmap image embedded in the .rtf at the beginning of the file? If your line counter happens to fall in the range between 0 and M-1, where M is the number of lines occupied by the image, you might scroll up until your line counter says M-4 but the richTextBox may very well place you AFTER the image end at line M. So how do you scroll to a position somewhere within the bitmap image?

The fact is, I don't think you do. But it's curious to wonder who, out there somewhere, would have run across a solution for that.

I figure out of desperation you can always use SB_TOP with your WM_SCROLL message and just set the display to top-of-file. Any more sophisticated notions, anyone?
Posted

1 solution

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

Solution 1

What if you work out the size of a line in pixels, and work out the size of the bitmap, so you know which lines are 'in the bitmap' ?
   
Comments
GAMerritt 23-Jan-11 11:50am
   
That's a good idea, but I wanted to avoid having to deal with the .rtf tags because that might mean having to add a filter for each type of embedded resource. I wondered if there was any way to get the info aka. SCROLLINFO but without having scrollbars enabled.

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




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