home *** CD-ROM | disk | FTP | other *** search
/ PC Format Collection 48 / SENT14D.ISO / tech / delphi / disk15 / scribble.pak / SCRBFORM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-08-24  |  1.6 KB  |  65 lines

  1. { Scribble Demo. This demo shows how to
  2.   implement a simple drawing program. Run the
  3.   program and draw on the canvas by holding
  4.   the left mouse button down.
  5.  
  6.   Property edits:
  7.     o Form1.Caption := 'Scribble';
  8.  
  9.   Event handlers:
  10.     o Generated for Form1's OnMouseDown,
  11.       OnMouseUp and OnMouseMove
  12.  
  13.   Variations:
  14.     o Try using the Object Inspector to vary
  15.       the canvas's pen color or pen width. You
  16.       can also use a color dialog (from the
  17.       palette's Dialogs page) to modify the
  18.       canvas's pen color at run-time.
  19. }
  20.  
  21. unit ScrbForm;
  22.  
  23. interface
  24.  
  25. uses WinTypes, WinProcs, Classes, Graphics, Controls, Forms;
  26.  
  27. type
  28.   TForm1 = class(TForm)
  29.     procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
  30.       Shift: TShiftState; X, Y: Integer);
  31.     procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
  32.       Shift: TShiftState; X, Y: Integer);
  33.     procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  34.   public
  35.     Drawing: Boolean;   { state variable }
  36.   end;
  37.  
  38. var
  39.   Form1: TForm1;
  40.  
  41. implementation
  42.  
  43. {$R *.DFM}
  44.  
  45. procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  46.   Shift: TShiftState; X, Y: Integer);
  47. begin
  48.   Drawing := True;         { set state variable }
  49.   Canvas.MoveTo(X, Y);     { move CP to mouse click X, Y }
  50. end;
  51.  
  52. procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  53.   Shift: TShiftState; X, Y: Integer);
  54. begin
  55.   Drawing := False;     { clear state variable }
  56. end;
  57.  
  58. procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  59.   Y: Integer);
  60. begin
  61.   if Drawing then Canvas.LineTo(X, Y);
  62. end;
  63.  
  64. end.
  65.