This is a migrated thread and some comments may be shown as answers.

Display dynamically tooltip for disabled RadRadioButton?

10 Answers 606 Views
Buttons, RadioButton, CheckBox, etc
This is a migrated thread and some comments may be shown as answers.
SUNIL
Top achievements
Rank 2
Iron
SUNIL asked on 23 Nov 2010, 07:04 PM
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

10 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 25 Nov 2010, 02:42 PM
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

0
SUNIL
Top achievements
Rank 2
Iron
answered on 25 Nov 2010, 04:59 PM
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
0
Emanuel Varga
Top achievements
Rank 1
answered on 25 Nov 2010, 08:05 PM
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
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 25 Nov 2010, 10:49 PM
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
0
SUNIL
Top achievements
Rank 2
Iron
answered on 26 Nov 2010, 07:23 AM
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
0
Richard Slade
Top achievements
Rank 2
answered on 26 Nov 2010, 08:37 AM
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
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 26 Nov 2010, 08:48 AM
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
0
SUNIL
Top achievements
Rank 2
Iron
answered on 26 Nov 2010, 04:24 PM
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
0
Emanuel Varga
Top achievements
Rank 1
answered on 26 Nov 2010, 04:26 PM
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
0
SUNIL
Top achievements
Rank 2
Iron
answered on 26 Nov 2010, 04:44 PM
Hi Emanuel,

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

Thanks for the solution.

Sunil
Tags
Buttons, RadioButton, CheckBox, etc
Asked by
SUNIL
Top achievements
Rank 2
Iron
Answers by
Emanuel Varga
Top achievements
Rank 1
SUNIL
Top achievements
Rank 2
Iron
Richard Slade
Top achievements
Rank 2
Share this question
or