delphi TColorToHex 与 HexToTColor


本文整理自网络,侵删。

 TColorToHex 与 HexToTColor
function TColorToHex(Color: TColor): string;
begin
Result :=
IntToHex(GetRValue(Color), 2) +
IntToHex(GetGValue(Color), 2) +
IntToHex(GetBValue(Color), 2);
end;

function HexToTColor(sColor: string): TColor;
begin
Result :=
RGB(
StrToInt(#36 + Copy(sColor, 1, 2)),
StrToInt(#36 + Copy(sColor, 3, 2)),
StrToInt(#36 + Copy(sColor, 5, 2))
);
end;

//测试:
procedure TForm1.Button1Click(Sender: TObject);
var
c: TColor;
s: string;
begin
c := clRed;
s := TColorToHex(c);
ShowMessage(s); //FF0000 (相当于 HTML 中的 #FF0000)

s := 'FF0000';
c := HexToTColor(s);
ShowMessage(BoolToStr(c=clRed)); //-1
Self.Color := c; //窗体将变红色
end;

相关阅读 >>

Delphi 判断字符串是否为纯字母组合

Delphi 实现一个程序在另一个程序内运行

Delphi编解码js字符串

Delphi 调用ie隐藏的命令

postmessage和sendmessage的区别

Delphi 自带单元字符md5加密

Delphi中实现密码框“大写锁定打开”的提示

Delphi shellexecute 发送邮件

Delphi中paramstr的用法

Delphi向当前窗口模拟键盘ctrl+v发送"粘贴"

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



打赏

取消

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

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

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

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

评论

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