Toast

TsgcHTMLComponent_Toast — 渲染一个 Bootstrap 5 toast 通知,带有标题、主体、时间戳、颜色和自动隐藏,由定位容器在屏幕上放置,适用于 Delphi、C++ Builder 和 .NET。

TsgcHTMLComponent_Toast

一个 toast 组件,发出 Bootstrap 5 toast 标记。设置标题、主体和颜色,然后读取 HTML 属性 — 或调用静态 Build 辅助方法,并将 toast 包装在定位的 BuildContainer 中。

组件类

TsgcHTMLComponent_Toast

渲染为

Bootstrap 5 toast 标记

语言

Delphi, C++ Builder, .NET

一行代码构建,或完整配置它

调用 Build(title, body, color, timestamp) 可快速创建 toast,并用 BuildContainer(toasts, position) 将其包装,或创建组件、设置 AutoHideDelay,然后读取 HTML

uses
  sgcHTML_Enums, sgcHTML_Component_Toast;

// One-line static helper (primary form):
var
  vToast: string;
begin
  vToast := TsgcHTMLComponent_Toast.Build('Saved',
    'Your changes were stored.', hcSuccess, 'just now');
  WebModule.Response := TsgcHTMLComponent_Toast.BuildContainer(vToast,
    tpTopEnd);
end;

// Or configure it fully:
var
  oToast: TsgcHTMLComponent_Toast;
begin
  oToast := TsgcHTMLComponent_Toast.Create(nil);
  try
    oToast.ToastID := 'saveToast';
    oToast.Title := 'Saved';
    oToast.Body := 'Your changes were stored.';
    oToast.ColorStyle := hcSuccess;
    oToast.Timestamp := 'just now';
    oToast.AutoHide := True;
    oToast.Delay := 4000;

    WebModule.Response := oToast.HTML;   // Bootstrap toast markup
  finally
    oToast.Free;
  end;
end;
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_Toast.hpp

// One-line static helper (primary form):
String toast = TsgcHTMLComponent_Toast::Build("Saved",
  "Your changes were stored.", hcSuccess, "just now");
String html = TsgcHTMLComponent_Toast::BuildContainer(toast, tpTopEnd);

// Or configure it fully:
TsgcHTMLComponent_Toast *oToast = new TsgcHTMLComponent_Toast(NULL);
try
{
  oToast->ToastID = "saveToast";
  oToast->Title = "Saved";
  oToast->Body = "Your changes were stored.";
  oToast->ColorStyle = hcSuccess;
  oToast->Timestamp = "just now";
  oToast->AutoHide = true;
  oToast->Delay = 4000;

  String body = oToast->HTML;   // Bootstrap toast markup
}
__finally
{
  delete oToast;
}
using esegece.sgcWebSockets;

// One-line static helper (primary form):
string toast = TsgcHTMLComponent_Toast.Build("Saved",
    "Your changes were stored.", TsgcHTMLColor.hcSuccess, "just now");
string html = TsgcHTMLComponent_Toast.BuildContainer(toast,
    TsgcHTMLToastPosition.tpTopEnd);

// Or configure it fully:
var t = new TsgcHTMLComponent_Toast();
t.ToastID = "saveToast";
t.Title = "Saved";
t.Body = "Your changes were stored.";
t.ColorStyle = TsgcHTMLColor.hcSuccess;
t.Timestamp = "just now";
t.AutoHide = true;
t.Delay = 4000;

string body = t.HTML;   // Bootstrap toast markup

关键属性与方法

您最常使用的成员。

内容

Title 设置页眉文本,Body 设置消息,Timestamp 设置小时间标签,Icon 设置标题前的内联图标。

颜色

ColorStyle 接受一个 TsgcHTMLColor(如 hcSuccesshcDanger);Color 接受原始的 Bootstrap 颜色名称字符串。

自动隐藏

AutoHideDelay 毫秒(默认 5000)后自动关闭 toast;将 AutoHide 设为 False 可使其保持固定。

标识

ToastID 分配元素 id,以便您可以从 JavaScript 显示或隐藏特定的 toast。

静态辅助方法

Build(title, body, color, timestamp) 返回一个 toast;BuildContainer(toasts, position) 将它们包装在固定的 toast-containerTsgcHTMLToastPosition)中。

输出

HTML 返回完整的 Bootstrap toast 标记 — 直接提供服务,或将其赋给页面模板的 BodyContent

继续探索

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

准备好开始了吗?

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