CheckBox

TsgcHTMLComponent_CheckBox — 一个带标签和数据集绑定的复选框(或拨动开关)输入,渲染 Bootstrap 5 form-check 标记,适用于 Delphi、C++ Builder 和 .NET。

TsgcHTMLComponent_CheckBox

一个独立的布尔输入,发出 Bootstrap form-check — 切换 Switch 可将其渲染为拨动开关。设置名称、标签和选中状态,然后读取 HTML 属性。它与同级的 Edit、Memo 和 RadioGroup 输入位于同一单元中。

组件类

TsgcHTMLComponent_CheckBox

渲染为

Bootstrap 5 form-check 输入

语言

Delphi, C++ Builder, .NET

创建它、配置它、渲染它

设置 NameLabel_Checked(可选地设置 Switch),然后读取 HTML(或将其放入 TsgcHTMLTemplate_Bootstrap 页面)。

uses
  sgcHTML_Component_Edit;

var
  oCheck: TsgcHTMLComponent_CheckBox;
begin
  oCheck := TsgcHTMLComponent_CheckBox.Create(nil);
  try
    oCheck.Name := 'newsletter';
    oCheck.Label_ := 'Subscribe to the newsletter';
    oCheck.Checked := True;
    oCheck.Switch := True;   // render as a toggle switch

    WebModule.Response := oCheck.HTML;   // Bootstrap form-check
  finally
    oCheck.Free;
  end;
end;

// Or bind it to a boolean dataset field:
oCheck.DataField := 'Active';
oCheck.DataSource := dsCustomer;
// includes: sgcHTML_Component_Edit.hpp

TsgcHTMLComponent_CheckBox *oCheck = new TsgcHTMLComponent_CheckBox(NULL);
try
{
  oCheck->Name = "newsletter";
  oCheck->Label_ = "Subscribe to the newsletter";
  oCheck->Checked = true;
  oCheck->Switch = true;   // render as a toggle switch

  String html = oCheck->HTML;   // Bootstrap form-check
}
__finally
{
  delete oCheck;
}
using esegece.sgcWebSockets;

var check = new TsgcHTMLComponent_CheckBox();
check.Name = "newsletter";
check.Label_ = "Subscribe to the newsletter";
check.Checked = true;
check.Switch = true;   // render as a toggle switch

string html = check.HTML;   // Bootstrap form-check

关键属性与方法

您最常使用的成员。

标识

Name 设置字段名称,Label_ 设置可见标题,CheckBoxID 设置元素 id(默认为 chk_<Name>)。

状态

Checked 设置初始值,Disabled 将控件置灰。

开关

Switch 将复选框替换为 Bootstrap form-switch 拨动开关,同时保持相同的复选框语义。

数据集绑定

DataField 加上已赋值的 DataSource 会从当前记录的布尔字段设置 Checked

输出与同级

HTML 返回带有输入框和标签的 form-check 包装器。同一单元声明了同级的 TsgcHTMLComponent_EditTsgcHTMLComponent_MemoTsgcHTMLComponent_RadioGroup 输入。

继续探索

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

准备好开始了吗?

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