delphi 设计一个有渐变色的标签


本文整理自网络,侵删。

 unit MLabel;
interface
uses
Windows Messages SysUtils Classes Graphics Controls Forms Dialogs
StdCtrls;
type
TColorStyle=(Horizontal Vertical);
type
TMLabel = class(TLabel)
private
CRed CGreen CBlue:Integer;
incRed incGreen incBlue:Integer;
FColor1: TColor;
FColor2: TColor;
FColorStyle: TColorStyle;
procedure SetColor1(const Value: TColor);
procedure SetColor2(const Value: TColor);
procedure SetColorStyle(const Value: TColorStyle);
procedure GetRGB(Color1 Color2:TColor);
{ Private declarations }
protected
{ Protected declarations }
procedure Paint;override;
public
{ Public declarations }
Constructor Create(AOwner:TComponent);override;
published
{ Published declarations }
property Color1:TColor read FColor1 Write SetColor1;
property Color2:TColor read FColor2 Write SetColor2;
property ColorStyle:TColorStyle read FColorStyle write SetColorStyle;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples' [TMLabel]);
end;
{ TMLabel }
constructor TMLabel.Create(AOwner: TComponent);
begin
inherited;
Width:=210;
Height:=40;
Font.Height:=43;
Font.Name:='楷体_GB2312';
FColor1:=clRed;
FColor2:=clWhite;
Canvas.Brush.Style:=bsClear;
Canvas.Font.Assign(Font);
end;
procedure TMLabel.GetRGB(Color1 Color2: TColor);
Var
R G B:Integer;
begin
CRed:=GetRValue(FColor1);
CGreen:=GetGValue(FColor1);
CBlue:=GetBValue(FColor1);
R:=GetRValue(FColor2);
G:=GetGValue(FColor2);
B:=GetBValue(FColor2);
incRed:=(R-CRed) div 10;
incGreen:=(G-CGreen) div 10;
incblue:=(B-CBlue) div 10;
end;
procedure TMLabel.Paint;
Var
i:Integer;
Rect:TRect;
begin
Rect:=ClientRect;
Canvas.Font.Color:=FColor1;
Canvas.TextRect(Rect 0 0 Caption);
for i:=1 to 10 do
Begin
if FColorStyle=Horizontal then
Rect.Right:=Rect.Right - (Rect.Right - Rect.Left) div 10
else
Rect.Bottom:=Rect.Bottom - (Rect.Bottom - Rect.Top) div 10;
Canvas.Font.Color:=RGB(CRed+incRed*i CGreen+incGreen*i CBlue+incBlue*i);
Canvas.TextRect(Rect 0 0 Caption);
End;
end;
procedure TMLabel.SetColor1(const Value: TColor);
begin
FColor1 := Value;
GetRGB(FColor1 FColor2);
Paint;
end;
procedure TMLabel.SetColor2(const Value: TColor);
begin
FColor2 := Value;
GetRGB(FColor1 FColor2);
Paint;
end;
procedure TMLabel.SetColorStyle(const Value: TColorStyle);
begin
FColorStyle := Value;
Paint;
end;
end.

相关阅读 >>

Delphi xe 与plc通讯(intcpserver 二进制)

Delphi tms web core webmemo 横竖滚动条

Delphi 为richedit设置行号

Delphi中对url进行编码和解码

Delphi debug与release的区别

Delphi 获取cpu monitor使用率

Delphi研究之驱动开发篇(一)--实现原理

Delphi b编码以及bt种子文件分析

Delphi 遍历pe文件

Delphi ado 动态建立.mdb数据库,表

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...