帮忙翻成bcb的(100分)

F

flmn

Unregistered / Unconfirmed
GUEST, unregistred user!
unit CoolProgressBar;
interface
uses
Windows, Messages,SysUtils, Classes, Controls,Graphics,Dialogs
,ExtCtrls;
type
TCoolProgressBar = class(TCustomControl)
private
{ Private declarations }
FTimer: TTimer;
FGradientStartColor:TColor;
FGradientEndColor:TColor;
FBorderColor:TColor;
FMax:Integer;
FMin:Integer;
FPosition:Integer;
procedure DrawGradientProgressImage(Canvas:TCanvas;ARect:TRect);
procedure OnTimer(Sender: TObject);
protected
{ Protected declarations }
procedure SetPosition(const Value:Integer);virtual;
procedure Paint;
override;
public
{ Public declarations }
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
published
{ Published declarations }
property Position:Integer read FPosition write SetPosition ;
property Color;
property Font;
property Visible;
end;

implementation
//------------------------------------------------------------------------------
constructor TCoolProgressBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
do
ubleBuffered:=True;
FBorderColor:=$00E7976B;
FMax:=100;
FMin:=0;
FPosition:=20;
Color:=clWhite;
Height:=30;
Width:=300;
FGradientStartColor:=clWhite;
FGradientEndColor:=clBlue;
FTimer:=TTimer.Create(self);
FTimer.Enabled:=true;
FTimer.Interval:=10;
FTimer.OnTimer:=OnTimer;
end;
//------------------------------------------------------------------------------
destructor TCoolProgressBar.Destroy;
begin
FTimer.Free;
inherited;
end;
//------------------------------------------------------------------------------
procedure TCoolProgressBar.SetPosition(const Value:Integer);
begin
if(Value<>FPosition) then
begin
FPosition:=Value;
Invalidate;
end;
end;
//------------------------------------------------------------------------------
procedure TCoolProgressBar.Paint;
var
cR:TRect;
Percent:Integer;
begin
;
cR:=GetClientRect;
With Canvasdo
begin

Font:=Self.Font;
//draw Border
Brush.Color:=FBorderColor;
FrameRect(cR);
//Draw ProgressBar
try
Percent:=Trunc((FPosition-FMin) / (FMax-FMin) * 100.0);
except
Percent:=0;
end;

if Percent<0 then
Percent:=0;
if(FPosition>0) then
begin
if Percent>0 then
begin

if Position>FMax then
begin

InflateRect(cR,-2, -2);
cR.Left:=cR.Left+Round(cR.Right * (Percent-FMax) /100 )
end
else

begin

InflateRect(cR,-2, -2);
cR.Right:=cR.Left+Round(cR.Right * Percent /100 )
end;
DrawGradientProgressImage(Canvas,cR);
end;

end;

end;

end;

//------------------------------------------------------------------------------
procedure TCoolProgressBar.DrawGradientProgressImage(Canvas:TCanvas;ARect:TRect);
var
i:Integer;
f:Single;
begin
for i:=0 to (ARect.Right-ARect.Left)-1do
begin
f:=i/(ARect.Right-ARect.Left);
Canvas.Pen.Color:=rgb(Round(GetRValue(FGradientEndColor)*f+GetRValue(FGradientStartColor)*(1-f)),
Round(GetGValue(FGradientEndColor)*f+GetGValue(FGradientStartColor)*(1-f)),
Round(GetBValue(FGradientEndColor)*f+GetBValue(FGradientStartColor)*(1-f)));
Canvas.MoveTo(ARect.Left+i,ARect.Top);
Canvas.LineTo(ARect.Left+i,ARect.Top+(ARect.Bottom-ARect.Top));
end;
end;
//------------------------------------------------------------------------------
procedure TCoolProgressBar.OnTimer(Sender: TObject);
begin
if Position<FMax then
begin
Position:=Position+1;
end
else
begin
if Position>=(FMax*2) then
begin
Position:=0;
end
else
begin
Position:=Position+1;
end;
end;
end;
end.
 
是个控件啊,自己在bcb中就可以使用了,不需要转换过来。
 
delphi代码在bcb不需要重写就可以使用
如果是一个单元可在BCB的工程中增加该pas单元再编译即可
编译完后, 要在那里用就使用
#include "CoolProgressBar.hpp"
即可, 注意hpp文件是编译后生成的
如果是控件,则安装方法与delphi相同, 只不过包的扩展名由dpk变成了bpk而已
 
我不需要控件的那么多功能,我想写得轻量级一些
 
如果不需要那么功能,把它的一部分分解出来做成新的控件就行了。做控件还是用Delphi写
代码的好,这样控件又可以被Delphi调用,又可以被CB调用。
如果你一定要转成CB代码,我也拦不住你,但建议你自己试着转转,大家都要忙着做手头的
活啊,而且两者有很多语法接近的地方。遇到问题时把问题的关键点抛出来,我等一定知无
不言。
 
多人接受答案了。
 

Similar threads

I
回复
0
查看
619
import
I
I
回复
0
查看
458
import
I
I
回复
0
查看
766
import
I
I
回复
0
查看
2K
import
I
I
回复
0
查看
1K
import
I
顶部