)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set different tooltips for the two buttons and the slider of the WinForms TrackBarEx?

Platform: WinForms |
Control: TextBoxExt |
Published Date: April 30, 2011 |
Last Revised Date: February 3, 2020

Tooltips

It is possible to set different tool tips for the two buttons and the slider by customizing the TrackBarEx.

C#

public class CustomTrackBarEx : TrackBarEx
{
   private Rectangle decRect, incRect, sliderRect;
   private ToolTip decTooltip = null;
   private ToolTip incTooltip = null;
   private ToolTip sliderTooltip = null;
   private string incBtnTooltip = "Increase";
   private string decBtnTooltip = "Decrease";
   private string sliderBtnTooltip = "Slider";
   public CustomTrackBarEx()
   {
      decTooltip = new ToolTip();
      decTooltip.Active = false;
      incTooltip = new ToolTip();
      incTooltip.Active = false;
      sliderTooltip = new ToolTip();
      sliderTooltip.Active = false;
   }
   protected override Rectangle DecreaseButtonBounds
   {
       get
       {
           decRect = base.DecreaseButtonBounds;
           return base.DecreaseButtonBounds;
       }
   }
   protected override Rectangle IncreaseButtonBounds
   {
       get
       {
           incRect = base.IncreaseButtonBounds;
           return base.IncreaseButtonBounds;
       }
   }
   protected override Rectangle SliderBounds
   {
      get
      {
          sliderRect = base.SliderBounds;
          return base.SliderBounds;
      }
   }
   protected override void Dispose(bool disposing)
   {
      if(incTooltip != null)
      {
         incTooltip.Dispose();
         incTooltip = null;
      }
      if(decTooltip != null)
      {
         decTooltip.Dispose();
         decTooltip = null;
      }
      if(sliderTooltip != null)
      {
         sliderTooltip.Dispose();
         sliderTooltip = null;
      }
      base.Dispose(disposing);
   }
   public string IncreaseButtonTooltip
   {
       get { return incBtnTooltip; }
       set { incBtnTooltip = value; }
   }
   public string DecreaseButtonTooltip
   {
       get { return decBtnTooltip; }
       set { decBtnTooltip = value; }
   }
   public string SliderBtnTooltip
   {
       get { return sliderBtnTooltip; }
       set { sliderBtnTooltip = value; }
   }
   protected override void OnMouseMove(MouseEventArgs e)
   {
       if(incRect.Contains(e.Location))
       {
          incTooltip.SetToolTip(this, IncreaseButtonTooltip);
          incTooltip.Active = true;
       }
       else
       {
          incTooltip.Active = false;
       }
       if(decRect.Contains(e.Location))
       {
          decTooltip.SetToolTip(this, DecreaseButtonTooltip);
          decTooltip.Active = true;
       }
       else
       {
          decTooltip.Active = false;
       }
       if(sliderRect.Contains(e.Location))
       {
          sliderTooltip.SetToolTip(this, SliderBtnTooltip);
          sliderTooltip.Active = true;
       }
       else
       {
          sliderTooltip.Active = false;
       }
       base.OnMouseMove(e);
   }
}

VB

Public Class CustomTrackBarEx Inherits TrackBarEx
    Private decRect, incRect, sliderRect As Rectangle
    Private decTooltip As ToolTip = Nothing
    Private incTooltip As ToolTip = Nothing
    Private sliderTooltip As ToolTip = Nothing
    Private incBtnTooltip As String = "Increase"
    Private decBtnTooltip As String = "Decrease"
    Private sliderBtnTooltip_Renamed As String = "Slider"
    Public Sub New()
        decTooltip = New ToolTip()
        decTooltip.Active = False
        incTooltip = New ToolTip()
        incTooltip.Active = False
        sliderTooltip = New ToolTip()
        sliderTooltip.Active = False
    End Sub
    Protected Overrides ReadOnly Property DecreaseButtonBounds() As Rectangle
        Get
             decRect = MyBase.DecreaseButtonBounds
             Return MyBase.DecreaseButtonBounds
        End Get
    End Property
    Protected Overrides ReadOnly Property IncreaseButtonBounds() As Rectangle
        Get
             incRect = MyBase.IncreaseButtonBounds
             Return MyBase.IncreaseButtonBounds
        End Get
    End Property
    Protected Overrides ReadOnly Property SliderBounds() As Rectangle
        Get
             sliderRect = MyBase.SliderBounds
             Return MyBase.SliderBounds
        End Get
    End Property
    Protected Overrides Overloads Sub Dispose(ByVal disposing As Boolean)
        If incTooltip IsNot Nothing Then
           incTooltip.Dispose()
           incTooltip = Nothing
        End If
        If decTooltip IsNot Nothing Then
           decTooltip.Dispose()
           decTooltip = Nothing
        End If
        If sliderTooltip IsNot Nothing Then
           sliderTooltip.Dispose()
           sliderTooltip = Nothing
        End If
        MyBase.Dispose(disposing)
    End Sub
    Public Property IncreaseButtonTooltip() As String
        Get
             Return incBtnTooltip
        End Get
        Set(ByVal value As String)
             incBtnTooltip = value
        End Set
    End Property
    Public Property DecreaseButtonTooltip() As String
        Get
            Return decBtnTooltip
        End Get
        Set(ByVal value As String)
            decBtnTooltip = value
        End Set
    End Property
    Public Property SliderBtnTooltip() As String
         Get
              Return sliderBtnTooltip_Renamed
         End Get
         Set(ByVal value As String)
              sliderBtnTooltip_Renamed = value
         End Set
    End Property
    Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
         If incRect.Contains(e.Location) Then
            incTooltip.SetToolTip(Me, IncreaseButtonTooltip)
            incTooltip.Active = True
         Else
            incTooltip.Active = False
         End If
         If decRect.Contains(e.Location) Then
            decTooltip.SetToolTip(Me, DecreaseButtonTooltip)
            decTooltip.Active = True
         Else
            decTooltip.Active = False
         End If
         If sliderRect.Contains(e.Location) Then
            sliderTooltip.SetToolTip(Me, SliderBtnTooltip)
            sliderTooltip.Active = True
         Else
            sliderTooltip.Active = False
         End If
         MyBase.OnMouseMove(e)
End Sub

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon