Warren  P
Warren P

Reputation: 68892

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

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?

Upvotes: 4

Views: 2815

Answers (1)

RRUZ
RRUZ

Reputation: 136391

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;

Upvotes: 4

Related Questions