syncfusion-winforms-rating

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Implementing Syncfusion WinForms Rating Control

实现Syncfusion WinForms Rating控件

The Rating Control provides an intuitive visual rating experience that allows users to select a number of stars (or other shapes) to represent a rating value. This control is ideal for user feedback, product reviews, quality ratings, and any scenario requiring visual rating input.
Rating控件提供直观的可视化评分体验,允许用户选择若干星形(或其他形状)来代表评分值。该控件非常适合用户反馈、产品评价、质量评分以及所有需要可视化评分输入的场景。

When to Use This Skill

何时使用该技能

Use this skill when the user needs to:
  • Star Rating Systems: Product ratings, reviews, user feedback with 1-5 stars
  • Custom Rating Shapes: Hearts for favorites, diamonds for quality, circles for simplicity
  • Half-Star Ratings: Fine-grained precision (3.5 stars, 4.5 stars) for detailed feedback
  • Feedback Forms: Customer satisfaction, service quality, experience ratings
  • Review Interfaces: Movie ratings, book reviews, app store ratings
  • Rating Display: Show read-only ratings or interactive rating input
  • Themed Rating Controls: Office 2007/2010/2016 styles with consistent UI appearance
  • Vertical/Horizontal Layouts: Adapt rating orientation to form design
当用户需要实现以下功能时可以使用本技能:
  • 星级评分系统: 产品评分、评价、1-5星的用户反馈
  • 自定义评分形状: 心形代表收藏、菱形代表质量、圆形代表简洁风格
  • 半星评分: 细粒度精度(3.5星、4.5星)的详细反馈
  • 反馈表单: 客户满意度、服务质量、体验评分
  • 评价界面: 电影评分、书评、应用商店评分
  • 评分展示: 展示只读评分或者可交互的评分输入框
  • 主题化评分控件: 保持UI外观统一的Office 2007/2010/2016样式
  • 垂直/水平布局: 适配表单设计调整评分控件的布局方向

Component Overview

组件概述

RatingControl (
Syncfusion.Windows.Forms.Tools.RatingControl
) is a versatile rating input control supporting:
  • 6 Built-in Shapes: Star, Circle, Triangle, Heart, Diamond, Kite
  • Custom Images: Use your own image assets for unique rating indicators
  • Precision Modes: Standard (full shapes) or Half (half-shape granularity)
  • Office Themes: Office2007, Office2010, Office2016 (Colorful, DarkGray, White, Black), Metro
  • Flexible Orientation: Horizontal or Vertical layout
  • Tooltip Support: Display additional information on hover
  • Custom Styling: Gradient colors, highlight/selection colors, border customization
Key Namespace:
Syncfusion.Windows.Forms.Tools
Assembly:
Syncfusion.Tools.Windows.dll
(and dependencies)

RatingControl
Syncfusion.Windows.Forms.Tools.RatingControl
)是一款多功能的评分输入控件,支持:
  • 6种内置形状: 星形、圆形、三角形、心形、菱形、风筝形
  • 自定义图片: 使用你自己的图片资源作为独特的评分指示器
  • 精度模式: 标准(完整形状)或半星(半形状粒度)
  • Office主题: Office2007、Office2010、Office2016(多彩、深灰、白色、黑色)、Metro
  • 灵活的布局方向: 水平或垂直布局
  • 工具提示支持: 鼠标悬停时展示额外信息
  • 自定义样式: 渐变颜色、高亮/选中颜色、边框自定义
核心命名空间:
Syncfusion.Windows.Forms.Tools
程序集:
Syncfusion.Tools.Windows.dll
(及相关依赖)

Documentation and Navigation Guide

文档与导航指南

Getting Started

入门指南

📄 Read: references/getting-started.md
When to read: User needs to install, configure, or create their first Rating control.
Topics covered:
  • Assembly deployment and NuGet package installation
  • Adding Rating control via designer (toolbox)
  • Adding Rating control via code
  • Setting rating values with the Value property
  • Built-in shapes quick overview
  • Basic implementation examples
📄 阅读: references/getting-started.md
适用场景: 用户需要安装、配置或者创建第一个Rating控件时。
涵盖主题:
  • 程序集部署和NuGet包安装
  • 通过设计器(工具箱)添加Rating控件
  • 通过代码添加Rating控件
  • 使用Value属性设置评分值
  • 内置形状快速概览
  • 基础实现示例

Shapes and Customization

形状与自定义

📄 Read: references/shapes-and-customization.md
When to read: User wants built-in shapes (star, heart, circle) or needs custom image-based rating indicators.
Topics covered:
  • 6 Built-in shapes: Star, Circle, Triangle, Heart, Diamond, Kite
  • Changing shapes with the Shape property
  • Custom image shapes using CustomImageCollection
  • NormalImage, HoverImage, SelectedImage configuration
  • Custom image fallback behavior
  • Half-image support for precision modes
📄 阅读: references/shapes-and-customization.md
适用场景: 用户想要使用内置形状(星形、心形、圆形)或者需要基于自定义图片的评分指示器时。
涵盖主题:
  • 6种内置形状:星形、圆形、三角形、心形、菱形、风筝形
  • 使用Shape属性修改形状
  • 使用CustomImageCollection实现自定义图片形状
  • NormalImage、HoverImage、SelectedImage配置
  • 自定义图片降级逻辑
  • 精度模式的半图支持

Precision and Values

精度与数值

📄 Read: references/precision-and-values.md
When to read: User needs half-star ratings (3.5 stars) or wants to control rating granularity.
Topics covered:
  • Precision modes: Standard vs Half
  • Half-star/half-shape rating configuration
  • Value property for setting and retrieving ratings
  • Precision with built-in shapes
  • Precision with custom images (requires half-images)
  • Rating value ranges and increments
📄 阅读: references/precision-and-values.md
适用场景: 用户需要半星评分(3.5星)或者想要控制评分粒度时。
涵盖主题:
  • 精度模式:标准 vs 半星
  • 半星/半形评分配置
  • 用于设置和获取评分的Value属性
  • 内置形状的精度适配
  • 自定义图片的精度适配(需要半图资源)
  • 评分值范围和步长

Styling and Appearance

样式与外观

📄 Read: references/styling-and-appearance.md
When to read: User wants Office themes, custom colors, gradient effects, or visual style customization.
Topics covered:
  • Visual styles: Default, Office2007, Office2010, Metro
  • Office2016 variants: Colorful, DarkGray, White, Black
  • OfficeColorScheme property (Blue, Silver, Black)
  • Custom gradient coloring with ApplyGradientColors
  • ItemHighlight and ItemSelection color properties
  • BackColor and BorderColor customization
📄 阅读: references/styling-and-appearance.md
适用场景: 用户想要使用Office主题、自定义颜色、渐变效果或者自定义视觉样式时。
涵盖主题:
  • 视觉样式:默认、Office2007、Office2010、Metro
  • Office2016变体:多彩、深灰、白色、黑色
  • OfficeColorScheme属性(蓝色、银色、黑色)
  • 通过ApplyGradientColors实现自定义渐变配色
  • ItemHighlight和ItemSelection颜色属性
  • 背景色和边框色自定义

Orientation and Tooltips

布局方向与工具提示

📄 Read: references/orientation-and-tooltips.md
When to read: User needs vertical rating layout or wants tooltips on rating items.
Topics covered:
  • Horizontal and Vertical orientation modes
  • Orientation property configuration
  • Tooltip enablement with ShowTooltip
  • Tooltip appearance customization
  • Layout considerations for vertical ratings

📄 阅读: references/orientation-and-tooltips.md
适用场景: 用户需要垂直评分布局或者想要给评分项添加工具提示时。
涵盖主题:
  • 水平和垂直布局模式
  • Orientation属性配置
  • 通过ShowTooltip启用工具提示
  • 工具提示外观自定义
  • 垂直评分的布局注意事项

Quick Start Example

快速入门示例

Basic Star Rating (5 Stars)

基础星级评分(5星)

csharp
using Syncfusion.Windows.Forms.Tools;

// Create rating control
RatingControl productRating = new RatingControl();
productRating.Location = new Point(20, 20);
productRating.Size = new Size(150, 30);

// Set initial value (3 out of 5 stars)
productRating.Value = 3;

// Add to form
this.Controls.Add(productRating);
csharp
using Syncfusion.Windows.Forms.Tools;

// 创建评分控件
RatingControl productRating = new RatingControl();
productRating.Location = new Point(20, 20);
productRating.Size = new Size(150, 30);

// 设置初始值(5星中的3星)
productRating.Value = 3;

// 添加到表单
this.Controls.Add(productRating);

Half-Star Precision Rating

半星精度评分

csharp
// Enable half-star precision
RatingControl preciseRating = new RatingControl();
preciseRating.Precision = PrecisionMode.Half;
preciseRating.Value = 3.5f; // 3.5 stars
csharp
// 启用半星精度
RatingControl preciseRating = new RatingControl();
preciseRating.Precision = PrecisionMode.Half;
preciseRating.Value = 3.5f; // 3.5星

Custom Shape (Hearts for Favorites)

自定义形状(心形收藏)

csharp
// Use heart shapes instead of stars
RatingControl favoriteRating = new RatingControl();
favoriteRating.Shape = Shapes.Heart;
favoriteRating.Value = 4;
csharp
// 用心形代替星形
RatingControl favoriteRating = new RatingControl();
favoriteRating.Shape = Shapes.Heart;
favoriteRating.Value = 4;

Office 2016 Themed Rating

Office 2016主题评分

csharp
// Apply Office 2016 Colorful theme
RatingControl themedRating = new RatingControl();
themedRating.Style = RatingControl.Style.Office2016Colorful;
themedRating.Value = 5;

csharp
// 应用Office 2016多彩主题
RatingControl themedRating = new RatingControl();
themedRating.Style = RatingControl.Style.Office2016Colorful;
themedRating.Value = 5;

Common Patterns

常见实现模式

Product Review Rating (Read-Only Display)

产品评价评分(只读展示)

csharp
// Display average rating (read-only)
RatingControl avgRating = new RatingControl();
avgRating.Value = 4.5f;
avgRating.Precision = PrecisionMode.Half;
avgRating.Enabled = false; // Read-only
When to use: Displaying aggregated ratings on product listings.
csharp
// 展示平均评分(只读)
RatingControl avgRating = new RatingControl();
avgRating.Value = 4.5f;
avgRating.Precision = PrecisionMode.Half;
avgRating.Enabled = false; // 只读
适用场景: 在产品列表页展示聚合评分。

Interactive Feedback Form

可交互反馈表单

csharp
// User can select rating
RatingControl feedbackRating = new RatingControl();
feedbackRating.Value = 0; // No initial selection
feedbackRating.Precision = PrecisionMode.Half;

// Handle rating changes
feedbackRating.RatingChanged += (s, e) => {
    float rating = feedbackRating.Value;
    MessageBox.Show($"User rated: {rating} stars");
};
When to use: Customer feedback forms, surveys, review submission.
csharp
// 用户可以选择评分
RatingControl feedbackRating = new RatingControl();
feedbackRating.Value = 0; // 无初始选择
feedbackRating.Precision = PrecisionMode.Half;

// 处理评分变化
feedbackRating.RatingChanged += (s, e) => {
    float rating = feedbackRating.Value;
    MessageBox.Show($"用户评分: {rating} 星");
};
适用场景: 客户反馈表单、调研、评价提交。

Vertical Rating Layout

垂直评分布局

csharp
// Vertical orientation for sidebar layouts
RatingControl verticalRating = new RatingControl();
verticalRating.Orientation = Orientationmode.Vertical;
verticalRating.Size = new Size(50, 200);
verticalRating.Value = 3;
When to use: Sidebar designs, narrow column layouts.
csharp
// 侧边栏布局使用垂直方向
RatingControl verticalRating = new RatingControl();
verticalRating.Orientation = Orientationmode.Vertical;
verticalRating.Size = new Size(50, 200);
verticalRating.Value = 3;
适用场景: 侧边栏设计、窄列布局。

Custom Color Gradient Rating

自定义渐变色评分

csharp
// Custom gradient colors (green to yellow)
RatingControl customRating = new RatingControl();
customRating.ApplyGradientColors = true;
customRating.ItemHighlightStartColor = Color.Green;
customRating.ItemHighlightEndColor = Color.YellowGreen;
customRating.ItemSelectionStartColor = Color.Gold;
customRating.ItemSelectionEndColor = Color.Orange;
customRating.Value = 4;
When to use: Branded color schemes, matching application themes.
csharp
// 自定义渐变颜色(绿到黄)
RatingControl customRating = new RatingControl();
customRating.ApplyGradientColors = true;
customRating.ItemHighlightStartColor = Color.Green;
customRating.ItemHighlightEndColor = Color.YellowGreen;
customRating.ItemSelectionStartColor = Color.Gold;
customRating.ItemSelectionEndColor = Color.Orange;
customRating.Value = 4;
适用场景: 品牌配色方案、适配应用主题。

Custom Image Rating

自定义图片评分

csharp
// Use custom images for rating
RatingControl customImageRating = new RatingControl();
customImageRating.Shape = Shapes.CustomImages;

CustomImageCollection images = new CustomImageCollection();
images.NormalImage = Properties.Resources.rating_normal;
images.HoverImage = Properties.Resources.rating_hover;
images.SelectedImage = Properties.Resources.rating_selected;

customImageRating.Images = images;
customImageRating.Value = 3;
When to use: Unique branding, custom icons, non-standard rating indicators.

csharp
// 使用自定义图片作为评分图标
RatingControl customImageRating = new RatingControl();
customImageRating.Shape = Shapes.CustomImages;

CustomImageCollection images = new CustomImageCollection();
images.NormalImage = Properties.Resources.rating_normal;
images.HoverImage = Properties.Resources.rating_hover;
images.SelectedImage = Properties.Resources.rating_selected;

customImageRating.Images = images;
customImageRating.Value = 3;
适用场景: 独特品牌风格、自定义图标、非标准评分指示器。

Key Properties

核心属性

Core Properties

基础属性

PropertyTypeDescriptionWhen to Use
Value
float
Current rating value (0 to number of items)Set/get rating selection
Precision
PrecisionMode
Standard or Half precisionEnable half-star ratings
Shape
Shapes
Star, Circle, Triangle, Heart, Diamond, Kite, CustomImagesChange rating indicator shape
Orientation
Orientationmode
Horizontal or VerticalVertical layout for sidebars
ShowTooltip
bool
Enable tooltips on rating itemsShow rating values on hover
属性类型描述适用场景
Value
float
当前评分值(0到评分项总数)设置/获取评分选择结果
Precision
PrecisionMode
标准或半星精度启用半星评分
Shape
Shapes
星形、圆形、三角形、心形、菱形、风筝形、自定义图片修改评分指示器形状
Orientation
Orientationmode
水平或垂直侧边栏使用垂直布局
ShowTooltip
bool
启用评分项的工具提示悬停时展示评分数值

Styling Properties

样式属性

PropertyTypeDescriptionWhen to Use
Style
RatingControl.Style
Visual style (Office2007/2010/2016, Metro)Apply Office themes
OfficeColorScheme
OfficeColorSchemes
Blue, Silver, Black color schemeOffice theme color variants
ApplyGradientColors
bool
Enable gradient color propertiesCustom gradient effects
ItemHighlightColor
Color
Hover state colorCustom hover appearance
ItemSelectionColor
Color
Selected state colorCustom selection appearance
属性类型描述适用场景
Style
RatingControl.Style
视觉样式(Office2007/2010/2016、Metro)应用Office主题
OfficeColorScheme
OfficeColorSchemes
蓝色、银色、黑色配色方案Office主题颜色变体
ApplyGradientColors
bool
启用渐变颜色属性自定义渐变效果
ItemHighlightColor
Color
悬停状态颜色自定义悬停外观
ItemSelectionColor
Color
选中状态颜色自定义选中外观

Custom Image Properties

自定义图片属性

PropertyTypeDescriptionWhen to Use
Images
CustomImageCollection
Custom image collectionUse custom rating images
Images.NormalImage
Image
Unselected state imageCustom default appearance
Images.HoverImage
Image
Hover state imageCustom hover appearance
Images.SelectedImage
Image
Selected state imageCustom selected appearance

属性类型描述适用场景
Images
CustomImageCollection
自定义图片集合使用自定义评分图片
Images.NormalImage
Image
未选中状态图片自定义默认外观
Images.HoverImage
Image
悬停状态图片自定义悬停外观
Images.SelectedImage
Image
选中状态图片自定义选中外观

Common Use Cases

常见使用场景

1. Product Rating Display

1. 产品评分展示

Scenario: E-commerce product listing with average ratings.
  • Use
    Value
    to display average (e.g., 4.3 stars)
  • Set
    Precision = PrecisionMode.Half
    for accurate display
  • Set
    Enabled = false
    for read-only
  • Read: precision-and-values.md
场景: 电商产品列表页展示平均评分。
  • 使用
    Value
    展示平均值(例如4.3星)
  • 设置
    Precision = PrecisionMode.Half
    实现精准展示
  • 设置
    Enabled = false
    实现只读效果
  • 阅读:precision-and-values.md

2. Customer Feedback Form

2. 客户反馈表单

Scenario: Service quality rating in feedback form.
  • Use
    Value = 0
    for no initial selection
  • Handle
    RatingChanged
    event to capture user input
  • Apply Office2016 theme for professional appearance
  • Read: getting-started.md, styling-and-appearance.md
场景: 反馈表单中的服务质量评分。
  • 设置
    Value = 0
    无初始选择
  • 监听
    RatingChanged
    事件捕获用户输入
  • 应用Office2016主题实现专业外观
  • 阅读:getting-started.mdstyling-and-appearance.md

3. Multi-Criteria Rating

3. 多维度评分

Scenario: Rate multiple aspects (Quality, Service, Value).
  • Create multiple RatingControl instances
  • Use descriptive labels for each rating
  • Consistent shape and style across all ratings
  • Read: shapes-and-customization.md
场景: 对多个维度评分(质量、服务、性价比)。
  • 创建多个RatingControl实例
  • 为每个评分项添加描述标签
  • 所有评分控件保持形状和样式统一
  • 阅读:shapes-and-customization.md

4. Favorite/Like System

4. 收藏/点赞系统

Scenario: Heart-based favorites (1-5 hearts).
  • Set
    Shape = Shapes.Heart
  • Use custom colors for romantic/favorite themes
  • Read: shapes-and-customization.md
场景: 基于心形的收藏功能(1-5颗心)。
  • 设置
    Shape = Shapes.Heart
  • 使用自定义颜色适配浪漫/收藏主题
  • 阅读:shapes-and-customization.md

5. Branded Rating UI

5. 品牌化评分UI

Scenario: Custom images matching brand identity.
  • Use
    Shape = Shapes.CustomImages
  • Provide NormalImage, HoverImage, SelectedImage
  • Include HalfImages for precision support
  • Read: shapes-and-customization.md
场景: 匹配品牌标识的自定义图片。
  • 使用
    Shape = Shapes.CustomImages
  • 提供NormalImage、HoverImage、SelectedImage资源
  • 包含半图资源支持精度模式
  • 阅读:shapes-and-customization.md

6. Vertical Rating Sidebar

6. 垂直评分侧边栏

Scenario: Sidebar with vertical rating display.
  • Set
    Orientation = Orientationmode.Vertical
  • Adjust Size for vertical layout
  • Use tooltips for value display
  • Read: orientation-and-tooltips.md

场景: 侧边栏展示垂直排列的评分。
  • 设置
    Orientation = Orientationmode.Vertical
  • 调整Size适配垂直布局
  • 使用工具提示展示数值
  • 阅读:orientation-and-tooltips.md

Events

事件

RatingChanged: Raised when the rating value changes (user interaction).
csharp
ratingControl1.RatingChanged += (sender, e) => {
    float newRating = ratingControl1.Value;
    // Process rating change
};

RatingChanged: 评分值发生变化时触发(用户交互导致)。
csharp
ratingControl1.RatingChanged += (sender, e) => {
    float newRating = ratingControl1.Value;
    // 处理评分变化
};

Best Practices

最佳实践

  1. Precision for Averages: Use
    PrecisionMode.Half
    when displaying aggregated ratings (4.5 stars)
  2. Read-Only Display: Set
    Enabled = false
    for non-interactive rating displays
  3. Consistent Shapes: Use the same shape across related rating controls
  4. Tooltips for Clarity: Enable
    ShowTooltip
    to show numeric values
  5. Custom Images: Provide all image states (Normal, Hover, Selected, HalfNormal, HalfSelected) for complete custom experience
  6. Theme Consistency: Match rating style to application theme (Office2016 variants)
  7. Value Initialization: Set
    Value = 0
    for new ratings, specific value for defaults

  1. 平均值使用半星精度: 展示聚合评分(4.5星)时使用
    PrecisionMode.Half
  2. 只读展示设置: 非交互的评分展示设置
    Enabled = false
  3. 形状保持统一: 相关的评分控件使用相同的形状
  4. 工具提示提升清晰度: 启用
    ShowTooltip
    展示数值
  5. 自定义图片规范: 提供所有状态的图片资源(正常、悬停、选中、半正常、半选中)实现完整的自定义体验
  6. 主题一致性: 评分样式与应用主题保持匹配(Office2016变体)
  7. 值初始化: 新建评分设置
    Value = 0
    ,有默认值的场景设置对应数值

Related Skills

相关技能

  • NumericUpDown: Alternative numeric input for precise values
  • TrackBar: Slider-based rating alternative
  • CheckBox/RadioButton: Binary or single-choice rating alternatives

  • NumericUpDown: 精准数值输入的替代方案
  • TrackBar: 滑动条形式的评分替代方案
  • CheckBox/RadioButton: 二选一或单选形式的评分替代方案

See Also

参考链接