TScrollBar
From Free Pascal wiki
Jump to navigationJump to search
│
Deutsch (de) │
English (en) │
suomi (fi) │
français (fr) │
日本語 (ja) │
>> LCL Components >> TScrollBar
This page explains how to use the TScrollBar component. When I mention to click on something, unless I explicitly say to right-click, you always left-click on the item in question.
Description
A control that allows the user to scroll the content of an associated control by moving an slider.
Usage
To use a TScrollBar on a form, you can simply select it on the Standard component pallet and place it by clicking on the form.
Small example
Move an image on your form depending on the scrollbar positions
- place two TScrollBars on your form
- in the object Inspector change the first scrollbar properties "Name" in "sbVert", "Child" in "sbVertical" and "Align" in "alRight"
- in the object Inspector change the second scrollbar properties "Name" in "sbHori" and "Align" in "alBottom"
- add a TPaintBox (additional component palette) to the form and set its "align" on "alClient"
- add a TImageList (common controls component palette) to the form
- upload an image in the ImageList:
- right-click the ImageList1 and select the ImageList Editor... from the pop-up menu
- Click on add and select an image (preferably a small icon 16 x 16 for example, Lazarus/images/icons/lazarus16x16)
- finish your selection with OK
- Choose your PaintBox, in the object inspector under events, create the event handler for the event OnPaint and write following code:
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
ImageList1.Draw(
Paintbox1.Canvas,
sbHori.Position * (PaintBox1.ClientWidth - ImageList1.Width) div sbHori.Max,
sbVert.Position * (Paintbox1.ClientHeight - ImageList1.Height) div sbVert.Max,
0);
end;
- Now let any change of the scrollbar positions repaint the form: create the event handler OnChange for a scrollbar and also call this for the other scrollbar:
procedure TForm1.sbVertChange(Sender: TObject);
begin
RePaint;
end;
Your little program could look like:
Siehe auch
Return To: LCL Components | — Previous: TComboBox | Next: TGroupBox |
--Michl 12:50, 12 June 2014 (CEST)