gpt4 book ai didi

vcl - 如何从 TMemo 控件获取滚动条通知?

转载 作者:行者123 更新时间:2023-12-04 16:34:34 25 4
gpt4 key购买 nike

我有一个 VCL TMemo控件,每次滚动文本时都需要通知。没有OnScroll事件并且滚动消息似乎没有传播到父表单。

知道如何获得通知吗?
作为最后的手段,我可​​以放置一个外部 TScrollBar并更新 TMemoOnScroll事件,但是当我在 TMemo 中移动光标或滚动鼠标滚轮时,我必须使它们保持同步...

最佳答案

您可以使用中介层类来处理 WM_VSCROLLWM_HSCROLL消息和 EN_VSCROLL EN_HSCROLL 通知代码(通过 WM_COMMAND 消息公开)。

试试这个样本

type
TMemo = class(Vcl.StdCtrls.TMemo)
private
procedure CNCommand(var Message: TWMCommand); message CN_COMMAND;
procedure WMVScroll(var Msg: TWMHScroll); message WM_VSCROLL;
procedure WMHScroll(var Msg: TWMHScroll); message WM_HSCROLL;
end;

TForm16 = class(TForm)
Memo1: TMemo;
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form16: TForm16;

implementation

{$R *.dfm}


{ TMemo }

procedure TMemo.CNCommand(var Message: TWMCommand);
begin
case Message.NotifyCode of
EN_VSCROLL : OutputDebugString('EN_VSCROLL');
EN_HSCROLL : OutputDebugString('EN_HSCROLL');
end;

inherited ;
end;

procedure TMemo.WMHScroll(var Msg: TWMHScroll);
begin
OutputDebugString('WM_HSCROLL') ;
inherited;
end;

procedure TMemo.WMVScroll(var Msg: TWMHScroll);
begin
OutputDebugString('WM_HSCROLL') ;
inherited;
end;

关于vcl - 如何从 TMemo 控件获取滚动条通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20463253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com