PageRenderTime 50ms CodeModel.GetById 17ms app.highlight 29ms RepoModel.GetById 1ms app.codeStats 1ms

/examples/scrollbar.pp

http://github.com/graemeg/lazarus
Pascal | 243 lines | 185 code | 25 blank | 33 comment | 1 complexity | a6c4466e8272c72c171ac776b63a8cf9 MD5 | raw file
  1{
  2 /***************************************************************************
  3                          Scrollbar - Example
  4                          ------------------
  5
  6                   Initial Revision  : Thursday Feb 01 2001
  7                   by Shane Miller
  8
  9                   Second Revision   : Saturday Jul 12 2014
 10                   by Jack D Linke
 11
 12 ***************************************************************************/
 13
 14 ***************************************************************************
 15 *                                                                         *
 16 *   This source is free software; you can redistribute it and/or modify   *
 17 *   it under the terms of the GNU General Public License as published by  *
 18 *   the Free Software Foundation; either version 2 of the License, or     *
 19 *   (at your option) any later version.                                   *
 20 *                                                                         *
 21 *   This code is distributed in the hope that it will be useful, but      *
 22 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 23 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 24 *   General Public License for more details.                              *
 25 *                                                                         *
 26 *   A copy of the GNU General Public License is available on the World    *
 27 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
 28 *   obtain it by writing to the Free Software Foundation,                 *
 29 *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
 30 *                                                                         *
 31 ***************************************************************************
 32}
 33program Scrollbar;
 34
 35{$mode objfpc}{$H+}
 36
 37uses
 38  Interfaces, Classes, StdCtrls, Forms, Buttons, Menus, ComCtrls,
 39  SysUtils, ExtCtrls, Controls, LazLogger;
 40
 41type
 42  TForm1 = class(TFORM)
 43    Scrollbar1 : TScrollbar;
 44    Button1 : TButton;
 45    Button2 : TButton;
 46    Button3 : TButton;
 47    Button4 : TButton;
 48    Label1 : TLabel;
 49    Label2 : TLabel;
 50    Label3 : TLabel;
 51    LabelMin : TLabel;
 52    LabelMax : TLabel;
 53    LabelPos : TLabel;
 54    Procedure Button1Clicked(Sender : TObject);
 55    Procedure Button2Clicked(Sender : TObject);
 56    Procedure Button3Clicked(Sender : TObject);
 57    Procedure Button4Clicked(Sender : TObject);
 58    Procedure Scrollbar1Changed(Sender : TObject);
 59    procedure Scrollbar1OnScroll(Sender: TObject; ScrollCode: TScrollCode; var ScrollPos: Integer);
 60  public
 61    constructor Create(AOwner: TComponent); override;
 62  protected
 63  end;
 64
 65var
 66  Form1 : TForm1;
 67
 68constructor TForm1.Create(AOwner: TComponent);	
 69begin
 70  inherited CreateNew(AOwner, 1);
 71  Caption := 'Scrollbar Demo v0.2';
 72  Height := 350;
 73  Width := 400;
 74
 75  ScrollBar1 := TSCrollBar.Create(self);
 76  with Scrollbar1 do
 77  Begin
 78    Parent := Self;
 79    Kind := sbVertical;
 80    Left := 100;
 81    Top := 50;
 82    Width := 15;
 83    Height := 300;
 84    Visible := True;
 85    OnChange := @scrollbar1Changed;
 86    OnScroll := @ScrollBar1OnScroll;
 87  end;
 88
 89  Button1 := TButton.create(self);
 90  with Button1 do
 91  begin
 92    Parent := self;
 93    Visible := True;
 94    Caption := 'Swap Orientation';
 95    Onclick := @button1clicked;
 96    Width := 100;
 97  end;
 98
 99  Button2 := TButton.create(self);
100  with Button2 do
101  begin
102    Parent := self;
103    Left := 100;
104    Visible := True;
105    Caption := 'Min + 20';
106    Onclick := @button2clicked;
107    Width := 100;
108  end;
109
110  Button3 := TButton.create(self);
111  with Button3 do
112  begin
113    Parent := self;
114    Left := 200;
115    Visible := True;
116    Caption := 'Max + 25';
117    Onclick := @button3clicked;
118    Width := 100;
119  end;
120
121  Button4 := TButton.create(self);
122  with Button4 do
123  begin
124    Parent := self;
125    Left := 300;
126    Visible := True;
127    Caption := 'Position + 5';
128    Onclick := @button4clicked;
129    Width := 100;
130  end;
131
132  Label1 := TLabel.create(self);
133  with Label1 do
134  begin
135    Parent := self;
136    Left := 125;
137    Top := 100;
138    Visible := True;
139    Caption := 'Scrollbar1.Min = ';
140    Width := 100;
141  end;
142
143  Label2 := TLabel.create(self);
144  with Label2 do
145  begin
146    Parent := self;
147    Left := 125;
148    Top := 130;
149    Visible := True;
150    Caption := 'Scrollbar1.Max = ';
151    Width := 100;
152  end;
153
154  Label3 := TLabel.create(self);
155  with Label3 do
156  begin
157    Parent := self;
158    Left := 125;
159    Top := 160;
160    Visible := True;
161    Caption := 'Scrollbar1.Position = ';
162    Width := 100;
163  end;
164
165  LabelMin := TLabel.create(self);
166  with LabelMin do
167  begin
168    Parent := self;
169    Left := 250;
170    Top := 100;
171    Visible := True;
172    Caption := IntToStr(Scrollbar1.Min);
173    Width := 100;
174  end;
175
176  LabelMax := TLabel.create(self);
177  with LabelMax do
178  begin
179    Parent := self;
180    Left := 250;
181    Top := 130;
182    Visible := True;
183    Caption := IntToStr(Scrollbar1.Max);
184    Width := 100;
185  end;
186
187  LabelPos := TLabel.create(self);
188  with LabelPos do
189  begin
190    Parent := self;
191    Left := 250;
192    Top := 160;
193    Visible := True;
194    Caption := IntToStr(Scrollbar1.Position);
195    Width := 100;
196  end;
197
198end;
199
200procedure TForm1.Button1Clicked(Sender : TObject);
201begin
202  debugln('[Button1Clicked]');
203  if ScrollBar1.Kind = sbHorizontal then
204    Scrollbar1.Kind := sbVertical else
205    Scrollbar1.kind := sbHorizontal;
206end;
207
208procedure TForm1.Button2Clicked(Sender : TObject);
209begin
210  ScrollBar1.Min := ScrollBar1.Min + 20;
211  LabelMin.Caption := IntToStr(ScrollBar1.Min);
212end;
213
214procedure TForm1.Button3Clicked(Sender : TObject);
215begin
216  ScrollBar1.Max := ScrollBar1.Max + 25;
217  LabelMax.Caption := IntToStr(ScrollBar1.Max);
218end;
219
220procedure TForm1.Button4Clicked(Sender : TObject);
221begin
222  Scrollbar1.Position := ScrollBar1.Position + 5;
223  LabelPos.Caption := IntToStr(ScrollBar1.Position);
224end;
225
226procedure TForm1.Scrollbar1Changed(Sender : TObject);
227begin
228  LabelMin.Caption := IntToStr(Scrollbar1.Min);
229  LabelMax.Caption := IntToStr(Scrollbar1.Max);
230  LabelPos.Caption := IntToStr(Scrollbar1.Position);
231end;
232
233procedure TForm1.Scrollbar1OnScroll(Sender: TObject; ScrollCode: TScrollCode; var ScrollPos: Integer);
234begin
235  DebugLn('.............Scrolled...............');
236end;
237
238begin
239  Application.Initialize; { calls InitProcedure which starts up GTK }
240  Application.CreateForm(TForm1, Form1);
241  Application.Run;
242end.
243