Mega Code Archive

 
Categories / Delphi / VCL
 

Bring Scrollbox Control into view

Title: Bring Scrollbox Control into view Question: Did you ever use a scroll box with lots of items, and want to focus a particular item? This routine will allow you to specify the control you want to "bring into view". Answer: // This will bring a particular control on a scrollbox "centered" into view. procedure tform2.center(acontrol:tcontrol); Var R:trect; t:integer; begin t:=(scrollbox1.height-acontrol.height) div 2; {new top} with scrollbox1 do begin R := AControl.ClientRect; R.TopLeft := ScreenToClient(AControl.ClientToScreen(R.TopLeft)); R.BottomRight := ScreenToClient(AControl.ClientToScreen(R.BottomRight)); with VertScrollBar do Position := Position - (t-R.Top); end; end;