菜鸟刚学类,把新建的类画在了image上,可是显示的是一张白色的背景上有一个图片,怎么让背景变成黑色的?我的代码如下...(65分)

  • 主题发起人 主题发起人 wanglong
  • 开始时间 开始时间
W

wanglong

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Menus;

type

TSprite = class
public
FBits: TBitmap;
constructor Create; virtual;
end;

TForm1 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
Image1: TImage;
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure N1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
wl:tsprite;
//定义位置
a,b:integer;
implementation

{$R *.dfm}

constructor TSprite.Create;
begin
inherited Create;

FBits := TBitmap.Create;
FBits.Width := 100;
FBits.Height := 100;
fbits.LoadFromFile('mytank.bmp');

end;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin


if key=vk_up then
begin
a:=a;
b:=b-10;
image1.Canvas.FillRect(image1.Canvas.ClipRect);
image1.Canvas.Draw(a,b,wl.FBits);
end;

if key=vk_down then
begin
a:=a;
b:=b+10;
image1.Canvas.FillRect(image1.Canvas.ClipRect);
image1.Canvas.Draw(a,b,wl.FBits);
end;

if key=vk_left then
begin
a:=a-10;
b:=b;
image1.Canvas.FillRect(image1.Canvas.ClipRect);
image1.Canvas.Draw(a,b,wl.FBits);
end;

if key=vk_right then
begin
a:=a+10;
b:=b;
image1.Canvas.FillRect(image1.Canvas.ClipRect);
image1.Canvas.Draw(a,b,wl.FBits);
end;

end;

procedure TForm1.N1Click(Sender: TObject);
begin
//如何把新创建的类显示到image控件上
wl:=tsprite.Create;
iMAGE1.Canvas.Draw(0,0,wl.FBits);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
form1.DoubleBuffered:=true;
end;

end.
 
在画图之前写:
IMAGE1.Canvas.Brush.Color := clBlack;
Image1.Canvas.FillRect(Rect(0,0,Image1.Width,Image1.Height));
Image1.Draw.....
 
接受答案了.
 
后退
顶部