Scroll selection to center after calling SearchText method

General TRichView support forum. Please post your questions here
Post Reply
saeid2016
Posts: 64
Joined: Wed Mar 16, 2016 11:56 am

Scroll selection to center after calling SearchText method

Post by saeid2016 » Wed Nov 29, 2017 9:10 am

Hello, The SearchText method selects the found text and scrolls it to view. Is it possible to scroll the selected text to center of RichViewEdit?

Sergey Tkachenko
Site Admin
Posts: 13833
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Scroll selection to center after calling SearchText method

Post by Sergey Tkachenko » Sat Dec 02, 2017 1:02 pm

You can implement it using undocumented methods:

Code: Select all

// searching for 'a' and centering the found line vertically
var
  rve: TCustomRichViewEdit;
  ItemNo, Offs: Integer;
begin
  RichViewEdit1.BeginUpdate;
  if RichViewEdit1.SearchText('a', [rvseoDown]) then
  begin
    rve := RichViewEdit1.TopLevelEditor;
    ItemNo := rve.CurItemNo;
    Offs := rve.OffsetInCurItem;
    rve.RVData.Item2DrawItem(ItemNo, Offs, ItemNo, Offs);
    RichViewEdit1.ScrollToDrawItem(rve.RVData, ItemNo, True);
  end;
  RichViewEdit1.EndUpdate;
end;

saeid2016
Posts: 64
Joined: Wed Mar 16, 2016 11:56 am

Re: Scroll selection to center after calling SearchText method

Post by saeid2016 » Sun Dec 03, 2017 6:40 am

Thanks a lot

Post Reply