程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> GdiPlus[35]: IGPGraphicsPath (二) 命中測試

GdiPlus[35]: IGPGraphicsPath (二) 命中測試

編輯:Delphi

本例測試圖:

GdiPlus[35]: IGPGraphicsPath (二) 命中測試

  本例代碼:

unit Unit1; 
 
interface 
 
uses 
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
 Dialogs; 
 
type 
 TForm1 = class(TForm) 
  procedure FormCreate(Sender: TObject); 
  procedure FormPaint(Sender: TObject); 
  procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); 
  procedure FormResize(Sender: TObject); 
 end; 
 
var 
 Form1: TForm1; 
 
implementation 
 
{$R *.dfm} 
 
uses GdiPlus; 
 
var 
 Path1,Path2,Path3: IGPGraphicsPath; 
 Pen: IGPPen; 
 
procedure TForm1.FormCreate(Sender: TObject); 
var 
 R: TRect; 
begin 
 Pen := TGPPen.Create($FFFF0000, 3); 
 
 Path1 := TGPGraphicsPath.Create; 
 Path2 := TGPGraphicsPath.Create; 
 Path3 := TGPGraphicsPath.Create; 
 
 Path1.AddLine(0, 0, ClientWidth, ClIEntHeight); 
 
 R := ClIEntRect; 
 InflateRect(R, -ClientWidth div 3, -ClIEntHeight div 3); 
 OffsetRect(R, -Trunc((R.Right-R.Left) * 0.6), -Trunc((R.Bottom-R.Top) * 0.6)); 
 Path2.AddRectangle(TGPRect.Create(R)); 
 
 OffsetRect(R, R.Right-R.Left, R.Bottom-R.Top); 
 Path3.AddEllipse(TGPRect.Create(R)); 
end; 
 
procedure TForm1.FormPaint(Sender: TObject); 
var 
 Graphics: IGPGraphics; 
begin 
 Graphics := TGPGraphics.Create(Handle); 
 with Graphics do 
 begin 
  DrawPath(Pen, Path1); 
  DrawPath(Pen, Path2); 
  DrawPath(Pen, Path3); 
 end; 
end; 
 
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); 
var 
 Pt: TGPPoint; 
 str: string; 
begin 
 Pt.Initialize(X, Y); 
 str := ''; 
 if Path2.IsVisible(Pt) then str := '在矩形內'; 
 if Path3.IsVisible(Pt) then str := '在橢圓內'; 
 
 if Path1.IsOutlineVisible(Pt, Pen) then str := '在直線上'; 
 if Path2.IsOutlineVisible(Pt, Pen) then str := '在矩形的邊線上'; 
 if Path3.IsOutlineVisible(Pt, Pen) then str := '在橢圓的圓周線上'; 
 
 if Text <> str then Text := str; 
end; 
 
procedure TForm1.FormResize(Sender: TObject); 
begin 
 OnCreate(Sender); 
 Repaint; 
end; 
 
end. 


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved