Marco Cantù 1998, Mastering Delphi 4
Project: SCROLL2.DPR
Project Structure
SCROLL2.DPR
program Scroll2;
uses
Forms,
ScrollF in 'ScrollF.pas' {Form2};
{$R *.RES}
begin
Application.CreateForm(TForm2, Form2);
Application.Run;
end.
SCROLLF.PAS
unit ScrollF;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm2 = class(TForm)
procedure FormPaint(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.DFM}
procedure TForm2.FormPaint(Sender: TObject);
var
X1, Y1: Integer;
begin
X1 := HorzScrollBar.Position;
Y1 := VertScrollBar.Position;
{draw a yellow line}
Canvas.Pen.Width := 30;
Canvas.Pen.Color := clYellow;
Canvas.MoveTo (30-X1, 30-Y1);
Canvas.LineTo (1970-X1, 1970-Y1);
{draw a blue line}
Canvas.Pen.Color := clNavy;
Canvas.MoveTo (30-X1, 1970-Y1);
Canvas.LineTo (1970-X1, 30-Y1);
{draw a fuchsia square}
Canvas.Pen.Color := clFuchsia;
Canvas.Brush.Style := bsClear;
Canvas.Rectangle (500-X1, 500-Y1,
1500-X1, 1500-Y1);
end;
end.
SCROLLF.DFM
object Form2: TForm2
Left = 156
Top = 112
Width = 496
Height = 379
HorzScrollBar.Range = 2000
VertScrollBar.Range = 2000
AutoScroll = False
Caption = 'Scroll2'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OnPaint = FormPaint
PixelsPerInch = 96
TextHeight = 13
end
Copyright Marco Cantù 1998