WEFX
WEFX

Reputation: 8562

How to change icon on a Telerik RadToggleButton in WinForms?

How do I add and change icons on a Telerik RadToggleButton in a WinForms application? I want to add something similar to the pushpins used on Telerik's documentation here.

I've tried to just change the button's Image property during my ToggleStateChanged event, but I can't see how to even reference the desired image.

Upvotes: 0

Views: 1316

Answers (1)

WEFX
WEFX

Reputation: 8562

I was eventually able to figure this out, once I saw how the Designer auto-code was assigning images to these buttons. You first have to add the images/icons to the project's Resources.resx file.

Then, the ToggleStateChanged event should look like this:

private void myToggleButton_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
    RadToggleButton myButton = (RadToggleButton)sender;

    switch (args.ToggleState)
    {
        case ToggleState.On:
            myButton.Image = global::myProject.Properties.Resources.toggleOn;
            break;
        case ToggleState.Off:
            myButton.Image = global::myProject.Properties.Resources.toggleOff;
            break;
        default:
            break;
    }
}

Upvotes: 1

Related Questions