How to get the size in pixels of the Blue bar when selecting

General TRichView support forum. Please post your questions here
Post Reply
Tong
Posts: 5
Joined: Fri Sep 07, 2007 7:50 am

How to get the size in pixels of the Blue bar when selecting

Post by Tong »

Hello,
I'm using TRichView, I want to control scrollbar exactly in my program,so I must determine the size(top,left,width,Height) in pixels of the Blue bar when I select a Item, could anyone give me a hint? Thanks.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I remember your question how to scroll to the selection in TRichView.
Please wait, I'll create an example.
Tong
Posts: 5
Joined: Fri Sep 07, 2007 7:50 am

Post by Tong »

Yes. How to scroll to the selection in TRichView like TRichEdit or TTreeView is difficult, but I 've found a method. I'll send you the code when I finish it.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

My suggestions are below, if the selection is not inside table cells.


var StartItemNo, StartOffs, EndItemNo, EndOffs,
StartDItemNo, StartDOffs, EndDItemNo, EndDOffs: Integer;
SelTop, SelBottom, VisTop, VisBottom: Integer;

RichView1.GetSelectionBounds(StartItemNo, StartOffs, EndItemNo, EndOffs, True);
if (StartItemNo<0) or ((StartItemNo=EndItemNo) and (StartOffs=EndOffs)) then
exit; // no selection
RichView1.RVData.Item2DrawItem(StartItemNo, StartOffs, StartDItemNo, StartDOffs);
RichView1.RVData.Item2DrawItem(EndItemNo, EndOffs, EndDItemNo, EndDOffs);

Selection top coordinate (all coordinates are relative to the top left corner of document, i.e. the top left corner of the scrollable area):
SelTop := RichView1.RVData.DrawItems[StartDItemNo].Top;
Selection bottom coordinate:
SelBottom := RichView1.RVData.DrawItems[EndDItemNo].Top+RichView1.RVData.DrawItems[EndDItemNo].Height;
(For more accurate calculation, you should find minimal RichView1.RVData.DrawItems.Top and maximal RichView1.RVData.DrawItems.Top+RichView1.RVData.DrawItems.Height, where i from StartDItemNo to EndDItemNo)

You can use RichView1.ScrollTo to scroll to these coordinates.
As for visible area, its top coordinate is
VisTop := RichView1.VScrollPos*RichView1.VScrollPos;
Its bottom coordinate:
VisBottom := VisTop+RichView1.ClientHeight;
Tong
Posts: 5
Joined: Fri Sep 07, 2007 7:50 am

Post by Tong »

Thank you very much.
But My solve is very interesting. I'll create a program to demo it and send you the code.
Post Reply