如何使用TScrollbar进行richedit;

发布于 2024-11-13 06:29:21 字数 76 浏览 3 评论 0原文

如何使用 Tscrollbar 进行 Richedit。

我的目的是在不同的面板中分离滚动条。

是否可以?

How to use Tscrollbar to Richedit.

My purpose is to separate the scrollbar in a deferent panel.

is it possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌能量女王 2024-11-20 06:29:21

您可以尝试这样做:

procedure TForm1.ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode; var ScrollPos: Integer);
var
  WParam: longint;

begin
  case ScrollCode of
    scLineUp: WParam := SB_LINEUP;
    scLineDown: WParam := SB_LINEDOWN;
    scPageUp: WParam := SB_PAGEUP;
    scPageDown: WParam := SB_PAGEDOWN;
    scEndScroll: WParam := SB_ENDSCROLL;
    scPosition: WParam := SB_THUMBPOSITION;
    scTrack: WParam := SB_THUMBTRACK;
    else
      exit;
  end;
  WParam := WParam or word(ScrollPos) shl 16;

  RichEdit1.Perform(WM_VSCROLL, WParam, 0);
end;

procedure TForm1.RichEdit1Change(Sender: TObject);
var
  ScrollInfo: TScrollInfo;

begin
  FillChar(ScrollInfo, SizeOF(ScrollInfo), 0);
  ScrollInfo.cbSize := SizeOf(ScrollInfo);
  ScrollInfo.fMask := SIF_RANGE or SIF_PAGE or SIF_POS;
  if GetScrollInfo(RichEdit1.Handle, SB_VERT, ScrollInfo) then
  begin
    ScrollBar1.Max := ScrollInfo.nMax;
    ScrollBar1.Min := ScrollInfo.nMin;
    ScrollBar1.PageSize := ScrollInfo.nPage;
    ScrollBar1.Position := ScrollInfo.nPos;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  RichEdit1Change(self);
end;

它会在发生任何更改时将 Scrollbar1: TScrollBar 与 RichEdit 的滚动信息同步,并模拟来自滚动条的 WM_VSCROLL 消息。但是,它要求 RichEdit 有自己的垂直滚动条可见,因为如果滚动信息不可见,则滚动信息不会更新。

AFAIK 没有其他方法来获取滚动数据,只是因为 RichEdit 控件在不需要时不会创建它们(ScrollBars 属性中的 ssNone)。

You can try this:

procedure TForm1.ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode; var ScrollPos: Integer);
var
  WParam: longint;

begin
  case ScrollCode of
    scLineUp: WParam := SB_LINEUP;
    scLineDown: WParam := SB_LINEDOWN;
    scPageUp: WParam := SB_PAGEUP;
    scPageDown: WParam := SB_PAGEDOWN;
    scEndScroll: WParam := SB_ENDSCROLL;
    scPosition: WParam := SB_THUMBPOSITION;
    scTrack: WParam := SB_THUMBTRACK;
    else
      exit;
  end;
  WParam := WParam or word(ScrollPos) shl 16;

  RichEdit1.Perform(WM_VSCROLL, WParam, 0);
end;

procedure TForm1.RichEdit1Change(Sender: TObject);
var
  ScrollInfo: TScrollInfo;

begin
  FillChar(ScrollInfo, SizeOF(ScrollInfo), 0);
  ScrollInfo.cbSize := SizeOf(ScrollInfo);
  ScrollInfo.fMask := SIF_RANGE or SIF_PAGE or SIF_POS;
  if GetScrollInfo(RichEdit1.Handle, SB_VERT, ScrollInfo) then
  begin
    ScrollBar1.Max := ScrollInfo.nMax;
    ScrollBar1.Min := ScrollInfo.nMin;
    ScrollBar1.PageSize := ScrollInfo.nPage;
    ScrollBar1.Position := ScrollInfo.nPos;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  RichEdit1Change(self);
end;

It synchronizes Scrollbar1: TScrollBar with the scroll info of the RichEdit upon any change in it and simulates WM_VSCROLL messages coming from the scrollbar. However, it requires the RichEdit to have its own vertical scrollbar visible, because the scroll info is not updated, if it is not visible.

There is AFAIK no other way to get the scroll data, simply because the RichEdit control doesn't create them if not needed (ssNone in ScrollBars property).

护你周全 2024-11-20 06:29:21

我不确定我是否理解这个问题,但如果我答对了,你最好的选择可能是在滚动框中进行丰富的编辑,并使用 Windows 消息来同步两者。

安德里亚

I am not sure I understand the question, but if I get it right, your best bet is probably have the rich edit in a scroll box and use windows messages to synchronize the two.

Andrea

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文