Getting Started with WinForms Rating
Below are the basic steps needed to get started with RadRating control in Visual Studio:
1. Drag RadRating from the Visual Studio Toolbox to the form.
Set the Caption to “The best movie ever”.
Set the SelectionMode property to HalfItem.
In the code behind subscribe to the ValueChanged event, where you can calculate and display the average rating:
Handling the ValueChanged event
double averageRating = 0;
int numberOfChanges = 0;
public RatingGettingStarted()
{
InitializeComponent();
this.radRating1.Caption = "The best movie ever";
this.radRating1.Description = "Your rating:";
this.radRating1.SelectionMode = Telerik.WinControls.UI.RatingSelectionMode.HalfItem;
this.radRating1.ValueChanged += radRating1_ValueChanged;
}
private void radRating1_ValueChanged(object sender, EventArgs e)
{
Telerik.WinControls.UI.RadRating rating = sender as Telerik.WinControls.UI.RadRating;
if (rating != null)
{
averageRating += (double)rating.Value;
numberOfChanges++;
double result = averageRating / numberOfChanges;
rating.Description = string.Format("Your rating: {0:F2}/{1}", result, rating.Maximum);
}
}
Private averageRating As Double = 0
Private numberOfChanges As Integer = 0
Public Sub New()
InitializeComponent()
Me.RadRating1.Caption = "The best movie ever"
Me.RadRating1.Description = "Your rating:"
Me.RadRating1.SelectionMode = Telerik.WinControls.UI.RatingSelectionMode.HalfItem
AddHandler Me.RadRating1.ValueChanged, AddressOf radRating1_ValueChanged
End Sub
Private Sub radRating1_ValueChanged(sender As Object, e As EventArgs)
Dim rating As Telerik.WinControls.UI.RadRating = TryCast(sender, Telerik.WinControls.UI.RadRating)
If rating IsNot Nothing Then
averageRating += CDbl(rating.Value)
numberOfChanges += 1
Dim result As Double = averageRating / numberOfChanges
rating.Description = String.Format("Your rating: {0:F2}/{1}", result, rating.Maximum)
End If
End Sub
5. Press F5 to run the application.
See Also
Telerik UI for WinForms Learning Resources
- Telerik UI for WinForms Rating Component
- Getting Started with Telerik UI for WinForms Components
- Telerik UI for WinForms Setup
- Telerik UI for WinForms Application Modernization
- Telerik UI for WinForms Visual Studio Templates
- Deploy Telerik UI for WinForms Applications
- Telerik UI for WinForms Virtual Classroom(Training Courses for Registered Users)
- Telerik UI for WinForms License Agreement)