Display dynamically tooltip for disabled RadRadioButton?

11 posts, 2 answers
  1. Sunil
    Sunil avatar
    230 posts
    Member since:
    Jan 2004

    Posted 23 Nov 2010 Link to this post

    I am using Q1 2008 SP1.
    I need to display different tooltips for the same RadRadioButton. Also, sometimes the radiobutton is disabled, and I want to still display a dynamic tooltip. By dynamic, I mean the tooltip text is decided in code at runtime rather than being fixed at design-time.

    How would I do this? The 'ToolTipTextNeeded' event allows for a constant tooltip to be displayed but not a dynamically changing tooltip, and so I cannot rely on this event.

    Thanks
    Sunil
  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 25 Nov 2010 Link to this post

    Hello Sunil,

    Why can't you use the ToolTipNeeded event for a dynamic tooltip? if you are not using the Tag property of the button, just set the tooltipText on that property and just read it in the ToolTipNeeded event.
    Or you can create a custom property and read it from that property, so you can use the tag for something else, like so:

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            radButton1.ButtonElement.SetValue(ButtonProperties.TagProperty, "This is some Custom Tag " + DateTime.Now.ToString());
            radButton1.ToolTipTextNeeded += new ToolTipTextNeededEventHandler(radButton1_ToolTipTextNeeded);
        }
     
        void radButton1_ToolTipTextNeeded(object sender, ToolTipTextNeededEventArgs e)
        {
            var buttonElement = sender as RadButtonElement;
            var toolTip = buttonElement.GetValue(ButtonProperties.TagProperty).ToString();
     
            e.ToolTipText = toolTip;
     
            // the following line is just to change the value of the property for the next time it displays
            radButton1.ButtonElement.SetValue(ButtonProperties.TagProperty, "This is some Custom Tag " + DateTime.Now.ToString());
        }
     
        public class ButtonProperties
        {
            public static readonly RadProperty TagProperty =
                RadProperty.Register("ToolTipText", typeof(object), typeof(RadButtonElement), new RadElementPropertyMetadata(null));
        }
     
    }

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga
    Telerik WinForms MVP

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Sunil
    Sunil avatar
    230 posts
    Member since:
    Jan 2004

    Posted 25 Nov 2010 Link to this post

    Hi Emanuel,

    Thanks for your help.

    Would the 'Tooltip' needed event fire even when the button is disabled? I need to show the tooltip even when the button is disabled.

    Thanks
    Sunil
  5. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 25 Nov 2010 Link to this post

    Hello again Sunil,

    Nothing will work on a disabled control, that's the whole point of making it disabled, but you could just fake that button being disabled, some other backcolor, something else, instead of disabling the actual button.

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP
  6. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 25 Nov 2010 Link to this post

    Hello Sunil,

    Emanuel is right about the disabled controls not showing tooltips, but there is another way. This may sound odd, but it does work:

    1: Add a RadPanel to the form.
    2: Make it exactly the same size as the control that may or may not be disabled
    3: Put the control (button for example) inside it
    4: Make the border of the panel invisible
    5: Make the background colour of the panel transparent

    Then you can set a tooltip for the panel, and a tooltip for the RadRadioButton. When the radio button is enabled, it will pick up the tooltip text for the RadRadioButton, when it is disabled, it will pick up the tooltip text for the panel

    Me.RadPanel1.Size = Me.RadRadioButton2.Size
    Me.RadRadioButton2.Enabled = False
    Me.RadPanel1.PanelElement.ToolTipText = "My Disabled Button tooltip"
    Me.RadRadioButton2.ButtonElement.ToolTipText = "My Enabled Button tooltip"
    Me.RadPanel1.PanelElement.PanelBorder.Visibility = ElementVisibility.Collapsed
    Me.RadPanel1.PanelElement.BackColor = Color.Transparent

    hope this helps, but if you have any other questions, just let me know.

    Richard
  7. Sunil
    Sunil avatar
    230 posts
    Member since:
    Jan 2004

    Posted 26 Nov 2010 Link to this post

    Hi Richard,

    What a great solution you provided.
    I really appreciate all your help.

    It works very well.
    I simply set the Dock property of the radButton to 'Fill' inside the radpanel and also set rapanel backcolor property to 'transparent'.

    Thanks
    Sunil
  8. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 26 Nov 2010 Link to this post

    Hi Sunil,

    I'm glad this helped you. Please remember to mark all suggestions that helped you as answer so others can find teh solution too.

    All the best
    Richard
  9. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 26 Nov 2010 Link to this post

    Hello again Sunil,

    There is one other thing you can do without the panel and other things.

    You can just make the:
    radButton1.ButtonElement.Enabled = false; // true

    And this will still cause the tooptip to be shown because just the button element is disabled,
    I would suggest creating some extensions for this, like so:
    public static class RadButtonExtensions
    {
        public static void MakeDisabled(this RadButton button)
        {
            button.ButtonElement.Enabled = false;
        }
     
        public static void MakeEnabled(this RadButton button)
        {
            button.ButtonElement.Enabled = true;
        }
    }

    and then just call them like:
    radButton1.MakeDisabled();
    //and
    radButton1.MakeEnabled();

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga
    Telerik WinForms MVP
  10. Sunil
    Sunil avatar
    230 posts
    Member since:
    Jan 2004

    Posted 26 Nov 2010 Link to this post

    Hi Emanuel,

    I will try out your solution and let you know, but a question for you.
    If I set the 'ButtonElement' property to disabled, will the button click event fire? Because if it does, then it will be a problem.

    Thanks
    Sunil
  11. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 26 Nov 2010 Link to this post

    Hello Sunil,

    No, the click event is fired by the ButtonElement, not by the control itself.

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga
    Telerik WinForms MVP
  12. Sunil
    Sunil avatar
    230 posts
    Member since:
    Jan 2004

    Posted 26 Nov 2010 Link to this post

    Hi Emanuel,

    I checked and the click event does not fire when ButtonElement is disabled.

    Thanks for the solution.

    Sunil
Back to Top
UI for WinForms is Visual Studio 2017 Ready