自动创建的image控件的图片如何清空???(100分)

  • 主题发起人 主题发起人 herogyf
  • 开始时间 开始时间
H

herogyf

Unregistered / Unconfirmed
GUEST, unregistred user!
程序自动建立了一个image,怎样在窗口关闭时清空该image内的picture。
 
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
image1.Picture.CleanupInstance;
image1.Hide;
end;
不知能否满足你的要求?
 
不行啊,静态的还可以,可是要求是清空动态的image里的picture.
 
image1.picture.graphic := nil;
 
我把我的源程序贴出来:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
var
image:timage;
bitmap:tbitmap;
begin
bitmap:=tbitmap.Create;
bitmap.LoadFromFile('e:/the 8/image/back.bmp');
image:=timage.Create(self);
image.Parent:=form1;
image.Width:=250;
image.Height:=180;
image.Stretch:=true;
image.Canvas.Draw(0,0,bitmap);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
.........................
end;
end.


如何在FormClose中实现image的清空。image1.picture.graphic := nil;是不行的。
 
用以下句子就行了:
image1.Picture.Free;
image1.Hide;//此句可以没有。
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
[RED]image:timage;
bitmap:tbitmap;[/RED]

public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
[BLUE]//var
//image:timage;
//bitmap:tbitmap;[/BLUE]
begin
bitmap:=tbitmap.Create;
bitmap.LoadFromFile('e:/the 8/image/back.bmp');
image:=timage.Create(self);
image.Parent:=form1;
image.Width:=250;
image.Height:=180;
image.Stretch:=true;
image.Canvas.Draw(0,0,bitmap);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
[RED]Image.free;
Bitmap.Free;[/RED]
.........................
end;
end.

 
多人接受答案了。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部