如何创建假冒加载屏幕'在德尔福

时间:2016-10-19 16:34:23

标签: delphi timer shapes

我一直在努力在德尔福创建一个加载屏幕,但我无法在任何地方找到帮助。

我正在为学校项目创建游戏,我想实现一个模仿加载屏幕的表单。

我想在屏幕上移动一个形状,我希望它留下一条线索(模仿一个进度条)。我知道你使用计时器来平滑它的进展,但我不确定如何正确使用计时器的形状。

如果有人能告诉我我必须使用哪些代码/功能,我将不胜感激。

此致 Kuzon。

1 个答案:

答案 0 :(得分:1)

使用计时器移动形状并留下痕迹:

每次计时器事件触发时,调整形状位置。 通过在每个计时器刻度上添加宽度,在这里也可以制作一个形状。

unit MoveShape;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls;

type
  TFormMoveShape = class(TForm)
    Shape1: TShape;
    Timer1: TTimer;
    Shape2: TShape;
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormMoveShape: TFormMoveShape;

implementation

{$R *.dfm}

const
  cMoveIncrement = 2;

procedure TFormMoveShape.Timer1Timer(Sender: TObject);
begin
  if (Shape1.Left + Shape1.Width  < Self.ClientWidth - cMoveIncrement) then
  begin
    Shape1.Left := Shape1.Left + cMoveIncrement;
    Shape2.Width := Shape2.Width + cMoveIncrement;
  end
  else
  begin
    Shape1.Left := 8;
    Shape2.Width := 8;
  end;
end;

end.
object FormMoveShape: TFormMoveShape
  Left = 0
  Top = 0
  Caption = 'Form27'
  ClientHeight = 336
  ClientWidth = 635
  Color = clBtnFace
  DoubleBuffered = True
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Shape2: TShape
    Left = 8
    Top = 112
    Width = 8
    Height = 41
    Brush.Color = clAqua
    Shape = stRoundRect
  end
  object Shape1: TShape
    Left = 8
    Top = 112
    Width = 137
    Height = 41
    Shape = stRoundRect
  end
  object Timer1: TTimer
    Interval = 50
    OnTimer = Timer1Timer
    Left = 512
    Top = 24
  end
end