How do I get the horizontal and vertical scroll bar position of TWinControl such as TSynEdit?

2.5k views Asked by At

In Delphi, in many TWinControl descendants, such as in my exact case, the TSynEdit control, how would I read the horizontal and vertical scroll bar position?

I have been searching around in the source code for my particular control, and in the base class documentation for TWinControl, and can't figure it out.

Is there a general VCL specific way to do this, or should I do this via Win32 API calls?

1

There are 1 answers

1
RRUZ On BEST ANSWER

The GetScrollBarInfo function is the way to get the scrollbars position of any TWinControl. You must pass the handle of the control, an OBJID_VSCROLL or OBJID_HSCROLL value and a SCROLLBARINFO structure to return the data.

Check this sample

var
 LBarInfo: TScrollBarInfo;
begin
 LBarInfo.cbSize := SizeOf(LBarInfo);
 if GetScrollBarInfo(SynEdit1.Handle, Integer(OBJID_VSCROLL), LBarInfo) then
  ShowMessage(Format('Left %d Top %d Height %d Width %d', [LBarInfo.rcScrollBar.Left, LBarInfo.rcScrollBar.Top, LBarInfo.rcScrollBar.Height, LBarInfo.rcScrollBar.Width]));
end;