Delphi TRect函数例子
生活随笔
收集整理的這篇文章主要介紹了
Delphi TRect函数例子
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
{
在網上看到個這個例子感覺還不錯,將它移到自己的博客里沒事的時候看看;
TRect
作用:保存一個矩形的左上角和右下角的坐標值;
聲明:
type TRect = packed record
case integer of
0:(Left, Top, Right, Botton:Integer);
1:(TopLeft, BottonRight:TPoint);
end;
由上面的TRect可知,TRect是一個記錄類型(TRect),保存了矩形的左上角右下角兩個點,4個坐標
或2個點的值。
這個聲明是Record類型使用Case子句的典型的例子。
當我們通TopLeft和BottonRight兩個點創建矩形時,可以傳遞兩個TPoint值或用Point函數產生他們;
}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
rectangle1, rectangle2:TRect;
begin
//用Rectangle來手工設置一個矩形;
Rectangle1.Left := 0;
rectangle1.Top := 0;
rectangle1.Right := 40;
rectangle1.Bottom := 60;
//再用Rect函數設置第二個矩形;
Rectangle2 := Rect(Point(20, 40), Point(60, 80));
//顯示每個矩形的左上角和左下角的坐標
ShowMessageFmt('Rectangle 1 coords = %d, %d, %d, %d',
[rectangle1.left,
rectangle1.top,
rectangle1.Right,
rectangle1.Bottom]);
ShowMessageFmt('Rectangle 2 coords = %d, %d, %d, %d',
[rectangle2.Left,
rectangle2.Top,
rectangle2.Right,
rectangle2.Bottom]);
end;
end.
總結
以上是生活随笔為你收集整理的Delphi TRect函数例子的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 数据结构设计_MYSQL 设
- 下一篇: mysql 5.7 my.cnf 为空_