unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, TeCanvas; type TForm1 = class(TForm) ButtonColor1: TButtonColor; ButtonColor2: TButtonColor; procedure FormCreate(Sender: TObject); procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormPaint(Sender: TObject); procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure ButtonColor1Click(Sender: TObject); procedure ButtonColor2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} uses GDIPAPI,GDIPOBJ; var flag:Boolean; pts:array[0..1] of TGPPoint; p:0..2; procedure TForm1.ButtonColor1Click(Sender: TObject); begin Repaint; end; procedure TForm1.ButtonColor2Click(Sender: TObject); begin Repaint; end; procedure TForm1.FormCreate(Sender: TObject); begin ButtonColor1.Caption:='颜色1 '; ButtonColor2.Caption:='颜色2 '; ButtonColor1.SymbolColor:=clLime; ButtonColor2.SymbolColor:=clBlack; pts[0].X:=8; pts[0].Y:=8; pts[1].X:=ClientWidth - 10; pts[1].Y:=ClientHeight - 10; end; procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin flag:=True; end; procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); var i:Integer; begin if flag then begin if p = 0 then Exit; pts[p - 1]:=MakePoint(x,y); Repaint; end else begin p:=0; Cursor:=crDefault; for I := 0 to Length(pts) - 1 do begin if PtInRect(Bounds((pts[i].X - 2),(pts[i].Y - 2),4,4),Point(x,y)) then begin p:=i + 1; Cursor:=crHandPoint; end; end; end; end; procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin flag:=False; end; procedure TForm1.FormPaint(Sender: TObject); var g:TGPGraphics; p:TGPPen; R:TGPRect; lb:TGPLinearGradientBrush; c1,c2:TGPColor; i:Integer; begin DoubleBuffered:=True; g:=TGPGraphics.Create(Canvas.Handle); g.Clear(aclWhite); p:=TGPPen.Create(aclRed); R:=MakeRect(20,40,ClientWidth - 40,ClientHeight - 50); c1:=ColorRefToARGB(ButtonColor1.SymbolColor); c2:=ColorRefToARGB(ButtonColor2.SymbolColor); lb:=TGPLinearGradientBrush.Create(TGPPoint(pts[0]),TGPPoint(pts[1]),c1,c2); g.FillEllipse(lb,r); p.SetColor(aclBlue); for I := 0 to 1 do begin g.DrawRectangle(p,(pts[i].X - 2),(pts[i].Y - 2),4,4); end; lb.Free; p.Free; g.Free; end; end.