delphi7中 实现点击Button1 来进行2张image的切换 我这样写哪位高手能帮忙改正一下
unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,F...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, jpeg, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
count:integer;//定义全局变量
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
Var
e1:boolean;
n:integer;
begin
count:= (count + 1);
e1:=false;
try
count:=(count div 2);
except
e1:=true;
end;
if e1 then
image1.Picture.LoadFromFile('D:\My Documents\My Pictures\123.jpg')
else
image1.Picture.LoadFromFile('D:\My Documents\My Pictures\456.jpg');
// 判断 根据其结果实行相应的处理
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
count:= 0;
end;
end. 展开
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, jpeg, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
count:integer;//定义全局变量
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
Var
e1:boolean;
n:integer;
begin
count:= (count + 1);
e1:=false;
try
count:=(count div 2);
except
e1:=true;
end;
if e1 then
image1.Picture.LoadFromFile('D:\My Documents\My Pictures\123.jpg')
else
image1.Picture.LoadFromFile('D:\My Documents\My Pictures\456.jpg');
// 判断 根据其结果实行相应的处理
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
count:= 0;
end;
end. 展开
3个回答
展开全部
按钮事件里只要这样就行了
count:= (count + 1);//用inc(count);更好
if count=1 then
image1.Picture.LoadFromFile('D:\My Documents\My Pictures\123.jpg')
else
image1.Picture.LoadFromFile('D:\My Documents\My Pictures\456.jpg');
if count=2 then count:=0 ;
count:= (count + 1);//用inc(count);更好
if count=1 then
image1.Picture.LoadFromFile('D:\My Documents\My Pictures\123.jpg')
else
image1.Picture.LoadFromFile('D:\My Documents\My Pictures\456.jpg');
if count=2 then count:=0 ;
展开全部
最简单的办法利用按钮的Tag属性(默认为0),本身是整型,可用Case语句,无须定义太多变量,如果就几张图片固定,建议用个数组,如楼上代码,我会这样写:
const imgs:array[0..1] of string =('D:\My Documents\My Pictures\123.jpg','D:\My Documents\My Pictures\456.jpg');
begin
with button1 do
begin
image1.Picture.LoadFromFile(imgs[tag]);
case Tag of
0:tag:=1;
1:tag:=0;
end;
end;
end;
const imgs:array[0..1] of string =('D:\My Documents\My Pictures\123.jpg','D:\My Documents\My Pictures\456.jpg');
begin
with button1 do
begin
image1.Picture.LoadFromFile(imgs[tag]);
case Tag of
0:tag:=1;
1:tag:=0;
end;
end;
end;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
count:= (count + 1); 该为 count:=count+1;
e1:=false; if (count mod 2)=0 then
try begin
count:=(count div 2); flag:=true;//(flag为私有或全局变量)将e1替换为flag;
except count:=0;
e1:=true; end
end; else
flag:=false;
e1:=false; if (count mod 2)=0 then
try begin
count:=(count div 2); flag:=true;//(flag为私有或全局变量)将e1替换为flag;
except count:=0;
e1:=true; end
end; else
flag:=false;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询