主题:如何才能让更多的图片在这个界面上同时运行,而且不出现混乱的局面?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, jpeg, StdCtrls;
type
Test=class(TThread)
public
constructor Create(CreateSuspended: Boolean);//构造但不唤醒
procedure CreateCar;
procedure Execute; override;
end;
TForm1 = class(TForm)
Image1: TImage;
PaintBox1: TPaintBox;
Button1: TButton;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
// procedure CreateCar;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
BitMap:TBitmap;
Ta:Test;
implementation
{$R *.dfm}
constructor Test.Create(CreateSuspended: Boolean);
begin
inherited Create(CreateSuspended);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
PaintBox1.Left:=Image1.Left;
PaintBox1.Top:=Image1.Top;
PaintBox1.Width:=Image1.Width;
PaintBox1.Height:=Image1.Height;
Form1.DoubleBuffered:=True;
Ta:=Test.Create(False);
end;
procedure Test.Execute;
begin
inherited;
Synchronize(CreateCar);
end;
procedure Test.CreateCar; // TForm1.
var
Rect:TRect;
begin
Try
BitMap:=TBitMap.Create;
Randomize;
Case Random(4) of
0://左边Left
begin
BitMap.LoadFromFile('Car1Right.bmp');
Rect.Left:=0; //Rect.Top:=0; //(Rect.Top >=0) and (Rect.Bottom <=Form1.Height-BitMap.Height)
Rect.Top:=Random(Form1.PaintBox1.Height-BitMap.Height+Form1.PaintBox1.top);
//showmessage('Form1.PaintBox1.top is:'+IntToStr(Rect.Top));
while Rect.Left <=Form1.PaintBox1.Width do
begin
Form1.Refresh;
Form1.PaintBox1.Canvas.Draw(Rect.Left,Rect.Top,BitMap);
Rect.Left:=Rect.Left+2;
end;
end;
1://上边Top
begin
BitMap.LoadFromFile('Car1Down.bmp');
Rect.Top:=0; // +Form1.PaintBox1.Height-BitMap.Height
Rect.Left:=Random(Form1.PaintBox1.Width-BitMap.Width);
Form1.PaintBox1.Canvas.Draw(Rect.Left,Rect.Top,BitMap);
while Rect.top <=Form1.PaintBox1.Height do
begin
Form1.Refresh;
Form1.PaintBox1.Canvas.Draw(Rect.Left,Rect.Top,BitMap);
Rect.Top:=Rect.Top+3;
end;
end;
2://右边Right
begin
BitMap.LoadFromFile('Car1Left.bmp');
Rect.Left:=Form1.PaintBox1.Width-BitMap.Width;
Rect.Top:=Random(Form1.PaintBox1.Height-BitMap.Height); // +Form1.PaintBox1.top
Form1.PaintBox1.Canvas.Draw(Rect.Left,Rect.Top,BitMap);
while Rect.Left>=0 do
begin
Form1.Refresh;
Form1.PaintBox1.Canvas.Draw(Rect.Left,Rect.Top,BitMap);
Rect.Left:=Rect.Left-4;
end;
end;
3://下边Bottom
begin
BitMap.LoadFromFile('Car1Up.bmp');
Rect.Left:=Random(Form1.PaintBox1.Width-BitMap.Width);
Rect.Top:=0+Form1.PaintBox1.Height-BitMap.Height; //PaintBox1 +Form1.PaintBox1.top
Form1.PaintBox1.Canvas.Draw(Rect.Left,Rect.Top,BitMap);
while Rect.top>=0 do
begin
Form1.Refresh;
Form1.PaintBox1.Canvas.Draw(Rect.Left,Rect.Top,BitMap);
Rect.Top:=Rect.Top-3;
end;
end;
end;
finally
BitMap.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Ta.CreateCar;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Button1Click(self);
end;
end.
//我的目的就是能够有多张图片同时能够运行在界面上,而不仅仅是一张图片,现在我的这个程序只有一张图片在这里来来去去,我要模拟的是现实生活中的问题,四个方向能够同时有图片移动以及产生,当某个地方有图片存在的时候那个地方不能够再产生图片,当这张图片移走之后才允许再在这个地方画图骗 同时如果运行的话这里需要将那四张图片换一下。
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, jpeg, StdCtrls;
type
Test=class(TThread)
public
constructor Create(CreateSuspended: Boolean);//构造但不唤醒
procedure CreateCar;
procedure Execute; override;
end;
TForm1 = class(TForm)
Image1: TImage;
PaintBox1: TPaintBox;
Button1: TButton;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
// procedure CreateCar;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
BitMap:TBitmap;
Ta:Test;
implementation
{$R *.dfm}
constructor Test.Create(CreateSuspended: Boolean);
begin
inherited Create(CreateSuspended);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
PaintBox1.Left:=Image1.Left;
PaintBox1.Top:=Image1.Top;
PaintBox1.Width:=Image1.Width;
PaintBox1.Height:=Image1.Height;
Form1.DoubleBuffered:=True;
Ta:=Test.Create(False);
end;
procedure Test.Execute;
begin
inherited;
Synchronize(CreateCar);
end;
procedure Test.CreateCar; // TForm1.
var
Rect:TRect;
begin
Try
BitMap:=TBitMap.Create;
Randomize;
Case Random(4) of
0://左边Left
begin
BitMap.LoadFromFile('Car1Right.bmp');
Rect.Left:=0; //Rect.Top:=0; //(Rect.Top >=0) and (Rect.Bottom <=Form1.Height-BitMap.Height)
Rect.Top:=Random(Form1.PaintBox1.Height-BitMap.Height+Form1.PaintBox1.top);
//showmessage('Form1.PaintBox1.top is:'+IntToStr(Rect.Top));
while Rect.Left <=Form1.PaintBox1.Width do
begin
Form1.Refresh;
Form1.PaintBox1.Canvas.Draw(Rect.Left,Rect.Top,BitMap);
Rect.Left:=Rect.Left+2;
end;
end;
1://上边Top
begin
BitMap.LoadFromFile('Car1Down.bmp');
Rect.Top:=0; // +Form1.PaintBox1.Height-BitMap.Height
Rect.Left:=Random(Form1.PaintBox1.Width-BitMap.Width);
Form1.PaintBox1.Canvas.Draw(Rect.Left,Rect.Top,BitMap);
while Rect.top <=Form1.PaintBox1.Height do
begin
Form1.Refresh;
Form1.PaintBox1.Canvas.Draw(Rect.Left,Rect.Top,BitMap);
Rect.Top:=Rect.Top+3;
end;
end;
2://右边Right
begin
BitMap.LoadFromFile('Car1Left.bmp');
Rect.Left:=Form1.PaintBox1.Width-BitMap.Width;
Rect.Top:=Random(Form1.PaintBox1.Height-BitMap.Height); // +Form1.PaintBox1.top
Form1.PaintBox1.Canvas.Draw(Rect.Left,Rect.Top,BitMap);
while Rect.Left>=0 do
begin
Form1.Refresh;
Form1.PaintBox1.Canvas.Draw(Rect.Left,Rect.Top,BitMap);
Rect.Left:=Rect.Left-4;
end;
end;
3://下边Bottom
begin
BitMap.LoadFromFile('Car1Up.bmp');
Rect.Left:=Random(Form1.PaintBox1.Width-BitMap.Width);
Rect.Top:=0+Form1.PaintBox1.Height-BitMap.Height; //PaintBox1 +Form1.PaintBox1.top
Form1.PaintBox1.Canvas.Draw(Rect.Left,Rect.Top,BitMap);
while Rect.top>=0 do
begin
Form1.Refresh;
Form1.PaintBox1.Canvas.Draw(Rect.Left,Rect.Top,BitMap);
Rect.Top:=Rect.Top-3;
end;
end;
end;
finally
BitMap.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Ta.CreateCar;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Button1Click(self);
end;
end.
//我的目的就是能够有多张图片同时能够运行在界面上,而不仅仅是一张图片,现在我的这个程序只有一张图片在这里来来去去,我要模拟的是现实生活中的问题,四个方向能够同时有图片移动以及产生,当某个地方有图片存在的时候那个地方不能够再产生图片,当这张图片移走之后才允许再在这个地方画图骗 同时如果运行的话这里需要将那四张图片换一下。