如何用程序控制RichEdit控件的ScrollBar滚动到最底部?

coolqiang 2000-08-31 05:23:00
我的程序中要通过下面的代码向RichEdit中不断输出文本,
RichEdit1.Lines.Add('aaaaaaaaaaaaaaaaaaaaa');
但是但超过一屏后,文本虽然输出了到了RichEdit中,但滚动条却不能自动滚动到最底
部,换用Memo控件就可以自动滚动,那么,如何利用RichEdit中实现呢?

...全文
1003 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
coolqiang 2000-09-04
  • 打赏
  • 举报
回复
OK,搞定!谢谢playpcgame。
playpcgame 2000-09-04
  • 打赏
  • 举报
回复
试试这个
RichEdit1.SelLength := 0;
RichEdit1.SelStart:=RichEdit1.GetTextLen;
RichEdit1.Perform( EM_SCROLLCARET, 0, 0 );
coolqiang 2000-09-04
  • 打赏
  • 举报
回复
我试过了,好像还是没有达到我的要求啊!
mophy 2000-09-01
  • 打赏
  • 举报
回复
如果你愿意,可以发送虚拟键值: ctrl + home
playpcgame 2000-09-01
  • 打赏
  • 举报
回复
看看下面的消息,使用参数SB_BOTTOM就可以满足你的要求,在插入字符串后向你的RichEdit发送这个消息就可以了

WM_VSCROLL
nScrollCode = (int) LOWORD(wParam); // scroll bar value
nPos = (short int) HIWORD(wParam); // scroll box position
hwndScrollBar = (HWND) lParam; // handle to scroll bar

Parameters
nScrollCode
Value of the low-order word of wParam. Specifies a scroll bar value that indicates the user's scrolling request. This parameter can be one of the following values: Value Meaning
SB_BOTTOM Scrolls to the lower right.
SB_ENDSCROLL Ends scroll.
SB_LINEDOWN Scrolls one line down.
SB_LINEUP Scrolls one line up.
SB_PAGEDOWN Scrolls one page down.
SB_PAGEUP Scrolls one page up.
SB_THUMBPOSITION The user has dragged the scroll box (thumb) and released the mouse button. The nPos parameter indicates the position of the scroll box at the end of the drag operation.
SB_THUMBTRACK The user is dragging the scroll box. This message is sent repeatedly until the user releases the mouse button. The nPos parameter indicates the position that the scroll box has been dragged to.
SB_TOP Scrolls to the upper left.


nPos
Value of the high-order word of wParam. Specifies the current position of the scroll box if the nScrollCode parameter is SB_THUMBPOSITION or SB_THUMBTRACK; otherwise, nPos is not used.
hwndScrollBar
Value of lParam. If the message is sent by a scroll bar, then hwndScrollBar is the handle to the scroll bar control. If the message is not sent by a scroll bar, hwndScrollBar is NULL.
coolqiang 2000-09-01
  • 打赏
  • 举报
回复
谢谢taxi,但是能否解释得详细一点!
我需要当RichEdit出现滚动条后,能每次都自动把滑块滑到最底部,我查看了API,知道用GetScrollRange、SetScrollPos可以搞定,但我对具体参数的类型设置不是很清楚,能否帮我说一说?或者做一个小程序演示一下?
playpcgame 2000-09-01
  • 打赏
  • 举报
回复
下面的代码不知道是不是能满足你的要求:
procedure TForm1.btnAddLineClick(Sender: TObject);
Var nLineCount:Integer;
nScrollCount:Integer;
begin
//取得当前RichEdit中的内容的行数
nLineCount:=SendMessage(RichEdit1.Handle ,EM_GETLINECOUNT ,0,0);
Richedit1.Lines.Add('aaaaaaaaaaaaaaa');
Richedit1.Lines.Add('aaaaaaaaaaaaaaa');
Richedit1.Lines.Add('aaaaaaaaaaaaaaa');
//计算出需要滚动的行数
nScrollCount:= SendMessage(RichEdit1.Handle ,EM_GETLINECOUNT ,0,0)-nLineCount;
SendMessage(RichEdit1.Handle,EM_LINESCROLL ,0,nCount);
end;
coolqiang 2000-09-01
  • 打赏
  • 举报
回复
谢谢playpcgame,但是我试过SB_BOTTOM,不行,因为它的结果是最后一行文字显示在第一行,与我的要求不符合,我是希望最后一行文字显示在RichEdit的底部,这样能看到上面的文字。
还是告诉我如何调用GetScrollRange吧!
taxi 2000-08-31
  • 打赏
  • 举报
回复
这是自动滚动一行
SendMessage(RichEdit1.Handle,WM_Vscroll,sb_LineDown,0);
taxi 2000-08-31
  • 打赏
  • 举报
回复
SendMessage(RichEdit1.Handle,WM_VScroll,sb_Bottom,0);

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧