ColorPicker
TsgcHTMLComponent_ColorPicker — 渲染原生 HTML5 颜色输入框,可选带有十六进制文本字段和一键式色板预设,适用于 Delphi、C++ Builder 和 .NET。
TsgcHTMLComponent_ColorPicker — 渲染原生 HTML5 颜色输入框,可选带有十六进制文本字段和一键式色板预设,适用于 Delphi、C++ Builder 和 .NET。
一个带标签的原生颜色 <input>。设置初始 Value,添加预设 Swatches,然后读取 HTML 属性(或调用静态 Build 辅助方法一行完成)。
TsgcHTMLComponent_ColorPicker
原生 HTML5 <input type="color"> + 色板
Delphi, C++ Builder, .NET
设置 FieldName、LabelText 和初始 Value,向 Swatches 添加一键式预设,然后读取 HTML — 或调用静态 Build 辅助方法。
uses
sgcHTML_Component_ColorPicker;
var
oColor: TsgcHTMLComponent_ColorPicker;
begin
oColor := TsgcHTMLComponent_ColorPicker.Create(nil);
try
oColor.FieldName := 'brand_color';
oColor.LabelText := 'Brand color';
oColor.Value := '#0d6efd';
oColor.ShowValueInput := True;
oColor.Swatches.Add('#0d6efd');
oColor.Swatches.Add('#198754');
oColor.Swatches.Add('#dc3545');
WebModule.Response := oColor.HTML; // color input + hex field + swatches
finally
oColor.Free;
end;
end;
// Or the static one-liner (field name, value, label):
Result := TsgcHTMLComponent_ColorPicker.Build('brand_color', '#0d6efd', 'Brand color');
// includes: sgcHTML_Component_ColorPicker.hpp
TsgcHTMLComponent_ColorPicker *oColor = new TsgcHTMLComponent_ColorPicker(NULL);
try
{
oColor->FieldName = "brand_color";
oColor->LabelText = "Brand color";
oColor->Value = "#0d6efd";
oColor->ShowValueInput = true;
oColor->Swatches->Add("#0d6efd");
oColor->Swatches->Add("#198754");
oColor->Swatches->Add("#dc3545");
String html = oColor->HTML; // color input + hex field + swatches
}
__finally
{
delete oColor;
}
// Or the static one-liner:
String html = TsgcHTMLComponent_ColorPicker::Build("brand_color", "#0d6efd", "Brand color");
using esegece.sgcWebSockets;
var color = new TsgcHTMLComponent_ColorPicker();
color.FieldName = "brand_color";
color.LabelText = "Brand color";
color.Value = "#0d6efd";
color.ShowValueInput = true;
color.Swatches.Add("#0d6efd");
color.Swatches.Add("#198754");
color.Swatches.Add("#dc3545");
string html = color.HTML; // color input + hex field + swatches
// Or the static one-liner:
string html2 = TsgcHTMLComponent_ColorPicker.Build("brand_color", "#0d6efd", "Brand color");
您最常使用的成员。
Value 预填充选择器(默认 #0d6efd);FieldName 设置输入框的 name,以便随表单提交。
LabelText 在选择器上方渲染一个可选的 form-label,通过 for 关联。
ShowValueInput 在选择器旁添加一个同步的文本输入框,用户可以直接输入或粘贴 #rrggbb 值。
Swatches(一个存放十六进制代码的 TStrings)渲染一排预设按钮;点击其中一个会在客户端更新选择器(及十六进制字段)。
Disabled 禁用两个输入框;ColorPickerID 设置元素 id(回退到 cp_<FieldName> 或自动生成的 id)。
Build(fieldName, value, labelText) 一行返回标记,无需管理实例。