home *** CD-ROM | disk | FTP | other *** search
- { Scribble Demo. This demo shows how to
- implement a simple drawing program. Run the
- program and draw on the canvas by holding
- the left mouse button down.
-
- Property edits:
- o Form1.Caption := 'Scribble';
-
- Event handlers:
- o Generated for Form1's OnMouseDown,
- OnMouseUp and OnMouseMove
-
- Variations:
- o Try using the Object Inspector to vary
- the canvas's pen color or pen width. You
- can also use a color dialog (from the
- palette's Dialogs page) to modify the
- canvas's pen color at run-time.
- }
-
- unit ScrbForm;
-
- interface
-
- uses WinTypes, WinProcs, Classes, Graphics, Controls, Forms;
-
- type
- TForm1 = class(TForm)
- procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- public
- Drawing: Boolean; { state variable }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- Drawing := True; { set state variable }
- Canvas.MoveTo(X, Y); { move CP to mouse click X, Y }
- end;
-
- procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- Drawing := False; { clear state variable }
- end;
-
- procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- begin
- if Drawing then Canvas.LineTo(X, Y);
- end;
-
- end.
-