Page 1 of 1
How to get the size in pixels of the Blue bar when selecting
Posted: Wed Sep 12, 2007 8:40 am
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.
Posted: Fri Sep 14, 2007 4:48 pm
by Sergey Tkachenko
I remember your question how to scroll to the selection in TRichView.
Please wait, I'll create an example.
Posted: Mon Sep 17, 2007 3:24 am
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.
Posted: Mon Sep 17, 2007 3:32 pm
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;
Posted: Thu Sep 20, 2007 2:30 am
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.