Back to Devexpress

RatingControl.BeforeShowToolTip Event

windowsforms-devexpress-dot-xtraeditors-dot-ratingcontrol-e2d45e40.md

latest9.0 KB
Original Source

RatingControl.BeforeShowToolTip Event

Occurs when the mouse pointer hovers over a rating scale item and allows you to display a unique hint for that item.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Events")]
public event RatingToolTipEventHandler BeforeShowToolTip
vb
<DXCategory("Events")>
Public Event BeforeShowToolTip As RatingToolTipEventHandler

Event Data

The BeforeShowToolTip event's data class is RatingToolTipEventArgs. The following properties provide information specific to this event:

PropertyDescription
HitTestGets information about the hit point.
TextGets or sets tooltip content.
ValueGets the rating value.

Remarks

The RatingControl supports regular and super tooltips.

Default Behavior

The RatingControl displays a regular tooltip with the rating scale value.

The ShowToolTips option controls whether to show tooltips on hover.

Customize Regular Tooltip Text

Use the following RatingControl API to specify tooltip text and title:

|

API

|

Description

| | --- | --- | |

ToolTip

|

Specifies tooltip text. You can use line breaks in regular tooltips.

| |

AllowHtmlTextInToolTip

|

Specifies whether to parse HTML tags in text.

| |

ToolTipTitle

|

Specifies the tooltip title.

| |

BeforeShowToolTip

|

Handle this event to customize the tooltip based on the rating value.

|

The following code snippet specifies tooltip text and title and changes the text based on the rating value:

csharp
public Form1() {
  ratingControl1.ToolTip = "Please leave your feedback";
  ratingControl1.ToolTipTitle = "How was your experience?";
  ratingControl1.BeforeShowToolTip += RatingControl1_BeforeShowToolTip;
}
void RatingControl1_BeforeShowToolTip(object sender, DevExpress.XtraEditors.Repository.RatingToolTipEventArgs e) {
  switch(e.Value) {
  case 1:
    e.Text = "Very bad";
    break;
  case 2:
    e.Text = "Bad";
    break;
  }
}
vb
Public Sub New()
  ratingControl1.ToolTip = "Please leave your feedback"
  ratingControl1.ToolTipTitle = "How was your experience?"
  AddHandler ratingControl1.BeforeShowToolTip, AddressOf RatingControl1_BeforeShowToolTip
End Sub
Private Sub RatingControl1_BeforeShowToolTip(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Repository.RatingToolTipEventArgs)
  Select Case e.Value
  Case 1
    e.Text = "Very bad"
  Case 2
    e.Text = "Bad"
  End Select
End Sub

Assign an Image to Regular Tooltips

Use the RatingControl‘s ToolTipIconType property to specify a predefined icon. The ToolTipController.IconSize property specifies icon size.

Assign a custom image as follows:

  1. Create a ToolTipController and assign it to the RatingControl.ToolTipController property.
  2. Create an image collection and assign it to the ToolTipController.ImageList property.
  3. Handle the ToolTipController.BeforeShow event. Use the e.ImageOptions parameter to assign a raster or vector image to the tooltip.

Note

The ToolTipIconType property has priority over e.ImageOptions. If you assign a custom image, set ToolTipIconType to None.

The following code snippet assigns a custom image to a tooltip:

Note

ratingControl1, toolTipController1, and svgImageCollection1 were created at runtime.

csharp
public Form1() {
  ratingControl1.ToolTipController = toolTipController1;
  toolTipController1.ImageList = svgImageCollection1;
  toolTipController1.BeforeShow += ToolTipController1_BeforeShow;
}
void ToolTipController1_BeforeShow(object sender, DevExpress.Utils.ToolTipControllerShowEventArgs e) {
  ToolTipController controller = sender as ToolTipController;
  if (e.SelectedControl == ratingControl1)
  e.ImageOptions.SvgImage = (controller.ImageList as SvgImageCollection)["3stars"];
}
vb
Public Sub New()
  ratingControl1.ToolTipController = toolTipController1
  toolTipController1.ImageList = svgImageCollection1
  AddHandler toolTipController1.BeforeShow, AddressOf ToolTipController1_BeforeShow
End Sub
Private Sub ToolTipController1_BeforeShow(ByVal sender As Object, ByVal e As DevExpress.Utils.ToolTipControllerShowEventArgs)
  Dim controller As ToolTipController = TryCast(sender, ToolTipController)
  If e.SelectedControl = ratingControl1 Then
  e.ImageOptions.SvgImage = (TryCast(controller.ImageList, SvgImageCollection))("3stars")
  End If
End Sub

Display a Super Tooltip

Use the control’s SuperTip property to assign a super tooltip. If you wish to use HTML tags in a super tooltip, enable the SuperToolTip.AllowHtmlText property.

Setting the ToolTipController.ToolTipType property to SuperTip converts existing regular tooltips to super tooltips.

Tip

Read the following help topic for information on how to customize super tooltips: Hints and Tooltips.

Example

The code below shows how to display a unique tooltip for each rating grade.

csharp
ratingControl1.Properties.FillPrecision = DevExpress.XtraEditors.Repository.RatingItemFillPrecision.Full;

private void ratingControl1_BeforeShowToolTip(object sender, DevExpress.XtraEditors.Repository.RatingToolTipEventArgs e) {
    int value = Convert.ToInt32(e.Value);
    switch (value) {
        case 1: e.Text = "Very Bad";
            break;
        case 2: e.Text = "Bad";
            break;
        case 3: e.Text = "Average";
            break;
        case 4: e.Text = "Good";
            break;
        case 5: e.Text = "Excellent";
            break;
    }
}
vb
ratingControl1.Properties.FillPrecision = DevExpress.XtraEditors.Repository.RatingItemFillPrecision.Full

private void ratingControl1_BeforeShowToolTip(Object sender, DevExpress.XtraEditors.Repository.RatingToolTipEventArgs e)
    Dim value As Integer = Convert.ToInt32(e.Value)
    Select Case value
        Case 1
            e.Text = "Very Bad"
        Case 2
            e.Text = "Bad"
        Case 3
            e.Text = "Average"
        Case 4
            e.Text = "Good"
        Case 5
            e.Text = "Excellent"
    End Select

See Also

ShowToolTips

RatingControl Class

RatingControl Members

DevExpress.XtraEditors Namespace