在没有滚动条的RichTextBox中以编程方式滚动浏览.rtf中的位图 [英] Programmatic scrolling past bitmaps in .rtf in a RichTextBox with no scrollbars

查看:71
本文介绍了在没有滚动条的RichTextBox中以编程方式滚动浏览.rtf中的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您关闭了RichTextBox滚动条(设置为None),并且正在使用从C#到user32.dll的SendMessage()调用来滚动它,那么在关闭滚动条时不会得到SCROLLINFO.这意味着您必须保留一个行计数器,并像往常一样在Lparam的低16位中使用SB_LINEUP和SB_LINEDOWN,但是由于要放在高16位中的位置通常是通过使用GetScrollInfo()读取SCROLLINFO来实现的,所以您不必即使您想发送SB_THUMBTRACK或SB_THUMBPOSITION也没有用,我认为此值不为零.

您仍然可以通过行计数器并仅将滚动例程调用到LINEUP或LINEDOWN来管理OK.如果需要滚动距离,可以预先设置richTextBox.Visible = false.文本区域将闪烁,但是如果您跳了2500行的距离,还算不错.并且您始终可以对显示的.rtf文件的背景色进行采样,并将RichTextBox处于打开状态的面板的背景色设置为该颜色.总而言之,尽管实际上并没有任何直接的方法可以通过编程方式滚动其中之一,但是即使是单行滚动也可以相当一致地完成.

但是,例如,如果在文件的开头将.bitf嵌入了位图图像,该怎么办?如果您的行计数器恰好落在0到M-1之间,其中M是图像占用的行数,则可以向上滚动直到行计数器显示M-4,但是richTextBox可能会在您放置之后图像在M行结束.那么如何滚动到位图图像中的某个位置?

事实是,我不认为你这样做.但奇怪的是,谁会在某个地方找到解决该问题的解决方案.

我发现绝望的是,您始终可以将SB_TOP与WM_SCROLL消息一起使用,并且只需将显示设置为文件顶部即可.任何更复杂的概念,有人吗?

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?

推荐答案

如果您计算出以像素为单位的行的大小,并计算出位图的大小,那该怎么办?线在位图中"?
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'' ?


这篇关于在没有滚动条的RichTextBox中以编程方式滚动浏览.rtf中的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆