TScrollBar: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: TScrollBar
| Old | New | Line | |
|---|---|---|---|
| 1 | + | A **TScrollBar**  is a control that allows the user to scroll the content of an associated control by moving an slider. | |
| 2 | + | ||
| 3 | + | ## Usage | |
| 4 | + | ||
| 5 | + | To use a TScrollBar on a [[TForm|form]], you can simply select it on the [[Standard tab]] of the [[Component Palette]] and place it by clicking on the form. | |
| 6 | + | ||
| 7 | + | ## Small example | |
| 8 | + | ||
| 9 | + | Move an image on your form depending on the scrollbar positions | |
| 10 | + | ||
| 11 | + | - place two TScrollBars on your form | |
| 12 | + | - in the object Inspector change the first scrollbar properties "Name" in "sbVert", "Kind" in "sbVertical" and "Align" in "alRight" | |
| 13 | + | - in the object Inspector change the second scrollbar properties "Name" in "sbHori" and "Align" in "alBottom" | |
| 14 | + | - add a [[TPaintBox]] (additional component palette) to the form and set its "align" on "alClient" | |
| 15 | + | - add a [[TImageList]] (common controls component palette) to the form | |
| 16 | + | - upload an image in the ImageList: | |
| 17 | + | - right-click the ImageList1 and select the *ImageList Editor...* from the pop-up menu | |
| 18 | + | - Click on *add* and select an image (preferably a small icon 16 x 16 for example, Lazarus/images/icons/lazarus16x16) | |
| 19 | + | - finish your selection with *OK* | |
| 20 | + | - Choose your PaintBox, in the object inspector under events, create the event handler for the event *OnPaint* and write following code: | |
| 21 | + | ||
| 22 | + | ``` pascal | |
| 23 | + | procedure TForm1.PaintBox1Paint(Sender: TObject); | |
| 24 | + | begin | |
| 25 | + | ImageList1.Draw( | |
| 26 | + | Paintbox1.Canvas, | |
| 27 | + | sbHori.Position * (PaintBox1.ClientWidth - ImageList1.Width) div sbHori.Max, | |
| 28 | + | sbVert.Position * (Paintbox1.ClientHeight - ImageList1.Height) div sbVert.Max, | |
| 29 | + | 0); | |
| 30 | + | end; | |
| 31 | + | </source> | |
| 32 | + | * 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: | |
| 33 | + | <source> | |
| 34 | + | procedure TForm1.sbVertChange(Sender: TObject); | |
| 35 | + | begin | |
| 36 | + | RePaint; | |
| 37 | + | end; | |
| 38 | + | ``` | |
| 39 | + | ||
| 40 | + | Your little program could look like: | |
| 41 | + | ||
| 42 | + |  | |
| 43 | + | ||
| 44 | + | ## See also | |
| 45 | + | ||
| 46 | + | - [[doc:lcl/stdctrls/tscrollbar.html|TScrollBar doc]] | |
| 47 | + | - [[TTrackBar]] | |
| 48 | + | - [[TScrollBox]] | |
| 49 | + | ||
| 50 | + | --- | |
| 51 | + | *From the Free Pascal wiki, page "TScrollBar", as it stood on 2020-03-01 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
