unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Imaging.pngimage,
Vcl.ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure ImageProgress(current:Integer;max:Integer; ImageWidth:integer;Image:TImage);
begin
if Max<>0 then Image.Width:=Trunc((current/max)*ImageWidth);
end;
var
i:Integer=0;
procedure TForm1.Button1Click(Sender: TObject);
begin
i:=0;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.DoubleBuffered:=true;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
i:=i+3;
sleep(50);
ImageProgress( i,100,144,Image1);
end;
end.
//image
//width
{
min =
//image1.=0;
max = //image1.=172;//Image1的宽度是172
position=
//pos=trunc((min/max)*100*1.72)=trunc((min/max)*ImageWidth);
}
procedure
ImageProgress(min:Integer;max:Integer;ImageWidth:integer;Image:TImage);
begin
if Max<>0 then Image.Width:=Trunc((min/max)*ImageWidth);
end;
ImageProgress(StrToInt(Edit1.Text),StrToInt(Edit2.Text),172,Image1);
/////////////////////////////////////////
unit Unit1;
interface
uses
Windows, Messages, SysUtils,
Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,
ComCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Image1:
TImage;
Timer1:
TTimer;
Bevel1:
TBevel;
Button3:
TButton;
Edit1:
TEdit;
Edit2:
TEdit;
Button2:
TButton;
Memo1:
TMemo;
procedure
Timer1Timer(Sender: TObject);
procedure FormCreate(Sender:
TObject);
procedure
Button2Click(Sender: TObject);
procedure Button3Click(Sender:
TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R
*.dfm}
procedure
TForm1.Timer1Timer(Sender: TObject);
var
min,max,p:integer;
begin
memo1.Clear;
///////////////////////////////////////
min:=StrToInt(Edit1.Text);
max:=StrToInt(Edit2.Text);
if Image1.Width<0 then Image1.Width:=0;
if Image1.Width>172 then
Image1.Width:=172;
p:=Trunc((min / max)*100*1.72);
Image1.Width:=p;
///////////////////////////////////////
memo1.Lines.Add(Format('µ±Ç°image1.width=%d',[p]));
memo1.Lines.Add( 'image1.width
MIN=0');
memo1.Lines.Add( 'image1.width MAX=172');
end;
procedure TForm1.FormCreate(Sender:
TObject);
begin
Image1.Width:=0;
Edit1.Text:='50';
Edit2.Text:='100';
end;
procedure TForm1.Button2Click(Sender:
TObject);
begin
if (Image1.Width>=0)and(Image1.Width<=172) then Edit1.Text:=IntToStr(StrtoInt(Edit1.text)+1);
end;
// 0=<image.width<=172
procedure TForm1.Button3Click(Sender:
TObject);
begin
if (Image1.Width>=0)and(Image1.Width<=172) then Edit1.Text:=IntToStr(StrtoInt(Edit1.text)-1);
end;
end.