回 帖 发 新 帖 刷新版面

主题:如何才能让更多的图片在这个界面上同时运行,而且不出现混乱的局面?

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. 

//我的目的就是能够有多张图片同时能够运行在界面上,而不仅仅是一张图片,现在我的这个程序只有一张图片在这里来来去去,我要模拟的是现实生活中的问题,四个方向能够同时有图片移动以及产生,当某个地方有图片存在的时候那个地方不能够再产生图片,当这张图片移走之后才允许再在这个地方画图骗            同时如果运行的话这里需要将那四张图片换一下。

回复列表 (共2个回复)

沙发

你好.我是全职网赚工作者.
如果你有时间有电脑.
想在网络上创业.请联系我..
项目绝对真实.详情QQ空间资料
加盟请联系 QQ908889846

板凳

这是一个互助的模式。
不推广人也有钱赚的。分A B两个网。
不推广的人在A网。推广的人 在B网。
B网推广的人帮助A网。
A网拿6000元出局。
B网就多了。
C易特元亨QQ919169870
奖励制度 
C易特更多资料C易特元亨QQ919169870
http://blog.sina.com.cn/cyite6
C易特奖励制度
http://blog.sina.com.cn/s/blog_6b2561440100l5r8.html

我来回复

您尚未登录,请登录后再回复。点此登录或注册