Scroll selection to center after calling SearchText method

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

Scroll selection to center after calling SearchText method

Post by saeid2016 »

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: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Scroll selection to center after calling SearchText method

Post by Sergey Tkachenko »

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: 73
Joined: Wed Mar 16, 2016 11:56 am

Re: Scroll selection to center after calling SearchText method

Post by saeid2016 »

Thanks a lot
Post Reply