TRichView文本编辑控件如何实现滚动选择文本

作者:控件中国网   出处:控件中国网   2015-09-22 09:44:48   阅读:7

问题:TRichView如何实现滚动选择文本?

代码:

uses CRVFData, CRVData, Math; 

procedure ShowSelection(rv: TCustomRichView); 

var RVData: TCustomRVFormattedData; 

    StartItemNo, StartOffs, EndItemNo, EndOffs: Integer; 

    i, StartDItemNo, StartDOffs, EndDItemNo, EndDOffs: Integer; 

    R: TRect; 

begin 

  // finding subdocument containing selection (a main document or a cell) 

  RVData := RV.RVData; 

  while RVData.GetChosenRVData<>nil do 

    RVData := TCustomRVFormattedData(RVData.GetChosenRVData); 

  // getting selection 

  RVData.GetSelectionBoundsEx(StartItemNo, StartOffs, EndItemNo, EndOffs, True); 

  if (StartItemNo<0) or (EndItemNo<0) then 

    exit; 

  // converting selection position from item indices to drawing item indices 

  RVData.Item2DrawItem(StartItemNo, StartOffs, StartDItemNo, StartDOffs); 

  RVData.Item2DrawItem(EndItemNo, EndOffs, EndDItemNo, EndDOffs); 

  // (roughly) calculating selection coordinates in local coordinates of RVData 

  with RVData.DrawItems[StartDItemNo] do 

    R := Bounds(Left, Top, Width, Height); 

  for i := StartDItemNo+1 to EndDItemNo do 

    with RVData.DrawItems[i] do begin 

      R.Left := Min(R.Left, Left); 

      R.Top := Min(R.Top, Top); 

      R.Right := Max(R.Right, Left+Width); 

      R.Bottom := Max(R.Bottom, Top+Height); 

    end; 

  // scrolling to the selection 

  RVData.ShowRectangle(R.Left, R.Top, R.Right-R.Left, R.Bottom-R.Top); 

end;

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat