Recent Posts
Selamat datang di Coding Delphi Land Weblog kumpulan source code pemogram delphi
(Bukan maksud untuk menggurui tetapi marilah kita berbagi ilmu tuk perkembangan kemajuan teknologi kita
Selasa, 26 September 2017
Draw in canvas
Source Code :
unit Mouse_Event_Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Spin;
type
TForm1 = class(TForm)
Panel1: TPanel;
Image1: TImage;
Panel2: TPanel;
SpinEdit1: TSpinEdit;
SpinEdit2: TSpinEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MouseButtonIsDown: boolean; // indicates if the mouse button is down
implementation
{$R *.DFM}
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
{if the mouse button is down, draw a line}
if MouseButtonIsDown then
Image1.Canvas.LineTo(X,Y);
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
{if the mouse button is not down, move the initial drawing position}
if not MouseButtonIsDown then
Image1.Canvas.MoveTo(X,Y);
{indicate that the mouse button is down so that drawing will occur}
MouseButtonIsDown := TRUE;
{if the right mouse button was clicked...}
if Button = MBRight then
begin
{...while the mouse button is held down...}
while MouseButtonIsDown = TRUE do
begin
{...simulate mouse movement by the specified amounts. the image
continues to receive regular mouse messages as if the mouse was
under user control}
Mouse_Event(MOUSEEVENTF_MOVE,SpinEdit1.Value,SpinEdit2.Value,0,0);
{update the screen and pause for a short amount of time}
Application.ProcessMessages;
Sleep(10);
end;
end;
end;
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
{set the mouse button down variable to off}
MouseButtonIsDown := FALSE;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
{initialize the initial drawing position}
Image1.Canvas.MoveTo(10,10);
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
{initialize the mouse button down variable}
MouseButtonIsDown := FALSE;
end;
end.
0 komentar:
Posting Komentar