delphi – 如何禁用TScrollBox的滚动查看行为?

delphi – 如何禁用TScrollBox的滚动查看行为?,第1张

概述我有一个TScrollBox,其RichEdit比滚动框大,因此两个侧滚动条都出现在滚动框中.然后我有一个调用RichEdit.SetFocus的函数DoTask. 当我向下滚动到我想要查看部分文本控件的位置,然后调用DoTask时,ScrollBox将自动滚动到RichEdit的顶部.我怎么能避免这种情况? 如您所愿,这里有一些建议: >以下列形式覆盖SetFocusedControl: fun 我有一个TScrollBox,其RichEdit比滚动框大,因此两个侧滚动条都出现在滚动框中.然后我有一个调用RichEdit.SetFocus的函数DoTask.

当我向下滚动到我想要查看部分文本控件的位置,然后调用DoTask时,ScrollBox将自动滚动到RichEdit的顶部.我怎么能避免这种情况?

解决方法 如您所愿,这里有一些建议:

>以下列形式覆盖SetFocusedControl:

function TForm1.SetFocusedControl(Control: TWinControl): Boolean;begin  if Control = RichEdit then    Result := True  else    Result := inherited SetFocusedControl(Control);end;

要么:

type  TCustomMemoAccess = class(TCustomMemo);function TForm1.SetFocusedControl(Control: TWinControl): Boolean;var  Memo: TCustomMemoAccess;  Scroller: TScrollingWinControl;  Pt: TPoint;begin  Result := inherited SetFocusedControl(Control);  if (Control is TCustomMemo) and (Control.Parent <> nil) and    (Control.Parent is TScrollingWinControl) then  begin    Memo := TCustomMemoAccess(Control);    Scroller := TScrollingWinControl(Memo.Parent);    SendMessage(Memo.Handle,EM_POSFROMCHAR,Integer(@Pt),Memo.SelStart);    Scroller.VertScrollbar.position := Scroller.VertScrollbar.position +      Memo.top + Pt.Y;  end;end;

>设置TScrollBox:

type  TScrollBox = class(Forms.TScrollBox)  protected    procedure autoScrollinVIEw(AControl: TControl); overrIDe;  end;procedure TScrollBox.autoScrollinVIEw(AControl: TControl);begin  if not (AControl is TCustomMemo) then    inherited autoScrollinVIEw(AControl);end;

要么:

procedure TScrollBox.autoScrollinVIEw(AControl: TControl);begin  if (AControl.top > VertScrollbar.position + ClIEntHeight) xor      (AControl.top + AControl.Height < VertScrollbar.position) then    inherited autoScrollinVIEw(AControl);end;

或者使用上述所有创意组合.你喜欢滚动的方式和时间只有你知道.

总结

以上是内存溢出为你收集整理的delphi – 如何禁用TScrollBox的滚动查看行为?全部内容,希望文章能够帮你解决delphi – 如何禁用TScrollBox的滚动查看行为?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1277798.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-09
下一篇2022-06-09

发表评论

登录后才能评论

评论列表(0条)

    保存