實現原理:
1.拖一個rectangle控制元件,Align屬性為TOP
2.拖一個Split控制元件,Align為Top
3.拖Rectangle,Align為Bottom
4.拖Split,Align為Bottom
5.左邊、右邊依次類推,
6.最後拖一個Rectangle,Align為Client,Stroke屬性中的Color為red。
具體程式碼:
unit UnitCheckIPN; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, FMX.Objects, FMX.Controls.Presentation; type TForm2 = class(TForm) RT: TRectangle; //RectTop ST: TSplitter; RL: TRectangle; SL: TSplitter; RB: TRectangle; SB: TSplitter; RR: TRectangle; SR: TSplitter; Rect: TRectangle; Image1: TImage; Button1: TButton; Button2: TButton; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } procedure SetRect(s:String); function GetRC: String; // 獲取 獲取當前矩形的位置 procedure SetRC(const Value: String); // 設定 給定x,y,w,h 矩形自動改變位置 public { Public declarations } property RC: String read GetRC write SetRC; // 將矩形的值設為屬性,讀為獲取rect的(x,y,width, height) 寫時為設定矩形的x,y,w,h end; var Form2: TForm2; implementation {$R *.fmx} procedure TForm2.Button1Click(Sender: TObject); begin RC:='103,128,301,203'; // end; procedure TForm2.Button2Click(Sender: TObject); begin ShowMessage(RC); // end; procedure TForm2.Button3Click(Sender: TObject); begin RC:='103,128,394,203'; end; function TForm2.GetRC: String; var x,y,w,h : Single; begin result:=''; y:=RT.Height+ST.Height; h:=Image1.Height - RT.Height - ST.Height - RB.Height - SB.Height; x:=RL.Width+SL.Width; w:=Image1.Width-RL.Width-SL.Width-RR.Width-SR.Width; result:=x.ToString()+','+y.ToString()+','+w.ToString()+','+h.ToString(); end; procedure TForm2.SetRC(const Value: String); var ss: TStringList; x,y,w,h: Integer; begin ss:=TStringList.Create; ss.CommaText:=Value; x:=ss[0].ToInteger(); y:=ss[1].ToInteger(); w:=ss[2].ToInteger(); h:=ss[3].ToInteger(); ss.Free; RT.Height:=y-ST.Height; RB.Height:=Image1.Height-(RT.Height + ST.Height + h + SB.Height); RL.Width:=x-SL.Width; RR.Width:=Image1.Width-(RL.Width+SL.Width+w+SR.Width); end; procedure TForm2.SetRect(s: String); var ss: TStringList; x,y,w,h: Integer; begin ss:=TStringList.Create; ss.CommaText:=s; x:=ss[0].ToInteger(); y:=ss[1].ToInteger(); w:=ss[2].ToInteger(); h:=ss[3].ToInteger(); ss.Free; RT.Height:=y-ST.Height; RB.Height:=Image1.Height-(RT.Height + ST.Height + h + SB.Height); RL.Width:=x-SL.Width; RR.Width:=Image1.Width-(RL.Width+SL.Width+w+SR.Width); end; end.
https://www.cnblogs.com/studypanp/p/4930471.html