This example effect chart:
Code files:Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs;
Type
TForm1 = Class (Tform)
Procedure Formcreate (Sender:tobject);
Procedure Formdestroy (Sender:tobject);
Procedure Formpaint (Sender:tobject);
Procedure Formmousedown (Sender:tobject; Button:tmousebutton;
Shift:tshiftstate; X, Y:integer);
Procedure Formmousemove (Sender:tobject; Shift:tshiftstate; X, Y:integer);
Procedure Formmouseup (Sender:tobject; Button:tmousebutton;
Shift:tshiftstate; X, Y:integer);
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Uses Gdipobj, GDIPAPI;
Var
Img:tgpimage;
Rt:trect;
Flag:boolean;
X1,y1:integer;
Procedure Tform1.formcreate (Sender:tobject);
Const
Imgpath = ' c:\temp\test.png ';
Var
W,h:integer;
Begin
If not fileexists (Imgpath) then Exit;
IMG: = tgpimage.create (Imgpath);
W: = img. getwidth;
H: = img. GetHeight;
Rt. Left: = (clientwidth-w) div 2;
Rt. Top: = (clientheight-h) div 2;
Rt. Right: = Rt. Left + W;
Rt. Bottom: = Rt. Top + H;
DoubleBuffered: = True;
End
Procedure Tform1.formdestroy (Sender:tobject);
Begin
Img. Free;
End
Procedure Tform1.formpaint (Sender:tobject);
Var
G:tgpgraphics;
Begin
G: = Tgpgraphics.create (Canvas.handle);
G.drawimage (IMG, Makerect) (Rt. Left, Rt. Top, IMG. GetWidth, IMG. GetHeight));
G.free;
End
Procedure Tform1.formmousedown (Sender:tobject; Button:tmousebutton;
Shift:tshiftstate; X, Y:integer);
Begin
If PtInRect (RT, point (x,y)) Then
Begin
X1: = X;
Y1: = Y;
Flag: = True;
End
End
Procedure Tform1.formmousemove (Sender:tobject; Shift:tshiftstate; X
Y:integer);
Begin
If not flag then Exit;
Offsetrect (RT, x-x1, Y-y1);
X1: = X;
Y1: = Y;
Repaint;
End
Procedure Tform1.formmouseup (Sender:tobject; Button:tmousebutton;
Shift:tshiftstate; X, Y:integer);
Begin
Flag: = False;
End
End.
Form file:object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 190
ClientWidth = 317
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Position = poDesktopCenter
OnCreate = FormCreate
OnDestroy = FormDestroy
OnMouseDown = FormMouseDown
OnMouseMove = FormMouseMove
OnMouseUp = FormMouseUp
OnPaint = FormPaint
PixelsPerInch = 96
TextHeight = 13
end