📄 bncthrd.pas
字号:
unit BncThrd;
interface
uses WinProcs,Classes,Graphics,ExtCtrls;
type
TBounceThread=class(TThread)
private
FShape:TShape;
FXSpeed:Integer;
FYSpeed:Integer;
procedure MoveShape;
protected
procedure Execute;override;
public
constructor Create(Suspended:Boolean;Shape:TShape;XSpeed,YSpeed:Integer);
property Shape:TShape read FShape;
end;
implementation
procedure TBounceThread.MoveShape;
//var MaxHeight,MaxWidth:Integer;
begin
with Fshape do begin
Left:=Left+FXSpeed;
Top:=Top+FYSpeed;
if(Left<0)or(Left+Width>Parent.Width)then
FXSpeed:=FXSpeed*-1;
if(Top<0)or(Top+Height>Parent.Height)then
FYSpeed:=FYSpeed*-1;
end;
end;
procedure TBounceThread.Execute;
begin
While not Terminated do
begin
Synchronize(MoveShape);
end;
end;
constructor TBounceThread.Create(Suspended:Boolean;Shape:TShape;XSpeed,YSpeed:Integer);
begin
inherited Create(Suspended);
FShape:=Shape;
FXSpeed:=XSpeed;{X轴走向的速度}
FYSpeed:=YSpeed;{Y轴走向的速度}
FreeOnTerminate:=True;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -