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.
How to get the size in pixels of the Blue bar when selecting
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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;
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;