在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
本例效果图:
DrawEllipse:绘制一个由边框(该边框由一对坐标、高度和宽度指定)定义的椭圆。
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 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); procedure FormPaint(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} uses GDIPAPI,GDIPOBJ; var x:Integer=20; y:Integer=20; w:Integer=100; h:Integer=50; f:Byte; a,b:Integer; p:TGPPen; procedure TForm1.FormCreate(Sender: TObject); begin p:=TGPPen.Create(aclRed,2); end; procedure TForm1.FormDestroy(Sender: TObject); begin p.Free; end; procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin f:=1; a:=x; b:=y; end; procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if (f=0) then Exit; {如果F为0,立即从当前的语句块中退出(注意:并不是退出程序)} if ssctrl in Shift then begin f:=2; Text:='ctrl键被按下,鼠标可调整大小'; end else Text:='没有按下 Ctrl,鼠标可调整位置'; a:=x - a; b:=y - b; Repaint; {重绘} a:=x; b:=y; end; procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin f:=0; end; procedure TForm1.FormPaint(Sender: TObject); var g:TGPGraphics; begin g:=TGPGraphics.Create(Canvas.Handle); g.Clear(aclWhite); case f of 1: begin inc(x,a); {相当于x:=x + a} inc(y,b); {相当于y:=y + b} end; 2: begin inc(w,a); {相当于w:=w + a} inc(h,b); {相当于h:=h + b} end; end; g.DrawEllipse(p,x,y,w,h); {画一个椭圆} g.Free; end; end. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论