📄 offsetrgnu.pas
字号:
unit OffsetRgnU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MovingRgn: HRGN; // a handle to the moving region
XVel, YVel: Integer; // the region's velocity
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
{create an elliptical region}
MovingRgn := CreateEllipticRgn(0, 0, 75, 75);
{initialize its velocity}
XVel := 1;
YVel := 1;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
{select the circular region as a clipping region for the form}
SelectClipRgn(Canvas.Handle, MovingRgn);
{draw the image in the invisible TImage onto the form. the circular
clipping region prevents any drawing outside of the circular region}
Canvas.Draw(Image1.Left, Image1.Top, Image1.Picture.Bitmap);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
RegionBounds: TRect; // holds the bounding rectangle of the region
begin
{retrieve the smallest rectangle that can be drawn around the circular region}
GetRgnBox(MovingRgn, RegionBounds);
{the bounding rectangle is used to determine if the circular region has
reached the edges of the screen. if so, reverse the velocity}
if (RegionBounds.Left<0) or (RegionBounds.Left>ClientRect.Right-75) then
XVel := 0-XVel;
if (RegionBounds.Top<0) or (RegionBounds.Top>ClientRect.Bottom-75) then
YVel := 0-YVel;
{move the region by its current velocity}
OffsetRgn(MovingRgn, XVel, YVel);
{repaint the form to show the results}
Repaint;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
{the region is no longer needed, so destroy it}
DeleteObject(MovingRgn);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -