unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, MICRODRAWOCXLib_TLB, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Label1: TLabel;
MicroDrawOcx1: TMicroDrawOcx;
Button1: TButton;
Button2: TButton;
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
self.Button1.Caption:='偏'#13+'移'#13+'封'#13+'闭'#13+'区'#13+'域'; //显示竖排文字
setwindowlong(self.Button1.Handle,gwl_style,getwindowlong(self.Button1.Handle,gwl_style)or bs_multiline);
self.Button2.Caption:='关'#13+'闭'#13+'程'#13+'序';
setwindowlong(self.Button2.Handle,gwl_style,getwindowlong(self.Button2.Handle,gwl_style)or bs_multiline);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
obj_count : integer;
i : integer;
obj_id : integer;
obj_type : integer;
pt : array <0..1> of double;
radius : double;
area : double;
begin
obj_count:= self.MicroDrawOcx1.GetSelectCount;
for i := 1 to obj_count do
begin
obj_id := self.MicroDrawOcx1.GetObject(i);
obj_type := self.MicroDrawOcx1.GetObjectType(obj_id);
if obj_type = MICRODRAWOCXLib_TLB.AS_TYPE_CIRCLE then
begin
self.MicroDrawOcx1.CreateHatchOffset(obj_id,10,10,0);//偏移封闭区域,最后一个参数缺省为0
self.MicroDrawOcx1.GetPoint(obj_id,MICRODRAWOCXLib_TLB.POS_CENTER,pt<0>);//得到圆心
radius := self.MicroDrawOcx1.GetReal(obj_id,MICRODRAWOCXLib_TLB.REAL_RADIUS);//得到半径
area := self.MicroDrawOcx1.GetReal(obj_id,MICRODRAWOCXLib_TLB.REAL_AREA);//得到面积
//显示属性
self.ListBox1.Items.Text := '偏移的元素为: 圆'#13#10+'偏移的距离为:10'#13#10;
self.ListBox1.Items.Text := self.ListBox1.Items.Text+'偏移的数量为 : 10'#13#10+'最大圆的面积为:'+floattostr(area);
self.ListBox1.Items.Text := self.ListBox1.Items.Text+'最大圆的半径 :'+floattostr(radius);
self.ListBox1.Items.Text := self.ListBox1.Items.Text+'圆心坐标为 :'+format('%.2f,%.2f',
self.MicroDrawOcx1.ZoomAll;
self.MicroDrawOcx1.RedrawAll;
end
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
application.Terminate; //退出程序
end;
end.