uses GdiPlus; procedure TForm1.FormPaint(Sender: TObject); var Graphics: IGPGraphics; BlackPen, GreenPen: IGPPen; Rect: TGPRect; begin Rect.Initialize(20, 20, 80, 80); Graphics := TGPGraphics.Create(Handle); BlackPen := TGPPen.Create($FF000000, 1.5); GreenPen := TGPPen.Create($FF00FF00, 10); //GreenPen.Alignment := PenAlignmentCenter; //这是默认值 Graphics.DrawRectangle(GreenPen, Rect); Graphics.DrawRectangle(BlackPen, Rect); Graphics.TranslateTransform(Rect.X + Rect.Width, 0); GreenPen.Alignment := PenAlignmentInset; Graphics.DrawRectangle(GreenPen, Rect); Graphics.DrawRectangle(BlackPen, Rect); end;