ColorPicker 组件 — sgcHTML | eSeGeCe

ColorPicker

TsgcHTMLComponent_ColorPicker — 渲染原生 HTML5 颜色输入框,可选带有十六进制文本字段和一键式色板预设,适用于 Delphi、C++ Builder 和 .NET。

TsgcHTMLComponent_ColorPicker

一个带标签的原生颜色 <input>。设置初始 Value,添加预设 Swatches,然后读取 HTML 属性(或调用静态 Build 辅助方法一行完成)。

组件类

TsgcHTMLComponent_ColorPicker

渲染为

原生 HTML5 <input type="color"> + 色板

语言

Delphi, C++ Builder, .NET

创建它、添加色板、渲染它

设置 FieldNameLabelText 和初始 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) 一行返回标记,无需管理实例。

继续探索

在线帮助此组件的完整 API 参考和使用指南。
所有 sgcHTML 组件浏览 80 多个组件的完整功能矩阵。
下载免费试用版30 天试用版附带 60.HTML 演示项目。
价格Single、Team 和 Site 授权,均含完整源代码。

准备好开始了吗?

下载免费试用版,开始在 Delphi、C++ Builder 和 .NET 中构建 Web 界面。