Rating

TsgcHTMLComponent_Rating — 渲染星级(符号)评分显示或输入,带有可选的隐藏表单字段,适用于 Delphi、C++ Builder 和 .NET。

TsgcHTMLComponent_Rating

一个评分组件,发出一行可按喜好设置大小和颜色的填充和空白符号,外加一个携带数值的可选隐藏输入框。设置数值和最大值,然后读取 HTML 属性。

组件类

TsgcHTMLComponent_Rating

渲染为

符号评分 + 隐藏表单输入

语言

Delphi, C++ Builder, .NET

创建它、设置数值、渲染它

设置 ValueMaxValue,选择颜色和符号,然后读取 HTML — 或调用静态 Build 辅助方法实现一行代码。

uses
  sgcHTML_Component_Rating;

var
  oRating: TsgcHTMLComponent_Rating;
begin
  oRating := TsgcHTMLComponent_Rating.Create(nil);
  try
    oRating.Value := 4;
    oRating.MaxValue := 5;
    oRating.Color := '#ffc107';
    oRating.ShowValue := True;
    oRating.InputName := 'score';
    oRating.ReadOnly := False;

    WebModule.Response := oRating.HTML;   // stars + hidden input
  finally
    oRating.Free;
  end;
end;

// Or the static one-liner (value, maxValue, color):
Result := TsgcHTMLComponent_Rating.Build(4, 5, '#ffc107');
// includes: sgcHTML_Component_Rating.hpp

TsgcHTMLComponent_Rating *oRating = new TsgcHTMLComponent_Rating(NULL);
try
{
  oRating->Value = 4;
  oRating->MaxValue = 5;
  oRating->Color = "#ffc107";
  oRating->ShowValue = true;
  oRating->InputName = "score";
  oRating->ReadOnly = false;

  String html = oRating->HTML;   // stars + hidden input
}
__finally
{
  delete oRating;
}

// Or the static one-liner:
String html = TsgcHTMLComponent_Rating::Build(4, 5, "#ffc107");
using esegece.sgcWebSockets;

var rating = new TsgcHTMLComponent_Rating();
rating.Value = 4;
rating.MaxValue = 5;
rating.Color = "#ffc107";
rating.ShowValue = true;
rating.InputName = "score";
rating.ReadOnly = false;

string html = rating.HTML;   // stars + hidden input

// Or the static one-liner:
string html2 = TsgcHTMLComponent_Rating.Build(4, 5, "#ffc107");

关键属性与方法

您最常使用的成员。

数值

Value 设置在 MaxValue(默认 5)中有多少个符号被填充;ShowValue 附加一个 value/max 标题。

模式

ReadOnly(默认 True)将评分渲染为静态显示;将其设为 False 以获得交互式输入。

颜色

Color 将填充符号的颜色设置为 CSS 字符串;当 Color 为空时,ColorStyleTsgcHTMLColor,如 hcWarning)选择一个 Bootstrap 颜色。

符号

FilledSymbolEmptySymbol 覆盖图标(默认为星形 ★);Size 设置字体大小。

表单绑定

设置 InputName 以发出携带数值的隐藏 <input>,使评分随表单一起回传。

静态辅助方法与输出

Build(value, maxValue, color) 用一行代码返回标记;HTML 返回符号行以及可选的隐藏输入框。

继续探索

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

准备好开始了吗?

下载免费试用版,为您的 Delphi、C++ Builder 或 .NET Web 应用添加星级评分。