3

I was wondering if there is a way to group standard windows form buttons together, such as the way radio buttons can be, where only one can be selected at a time. I have four option buttons on my form, but only want one button to be able to be selected, and the background colour to change for the selected button, but if another button is pressed then to remove the background colour on the previous button and change the colour on the new button.

Sorry if this doesn't make sense

Thanks

Dean Lewis
  • 89
  • 7
  • You're going to need to provide a code sample to show us what you have tried! – blueberryredbull Apr 29 '15 at 10:55
  • 1
    Are you sure you shouldn't be using radio buttons? This doesn't sound like regular buttons at all. What does it mean to have a button selected? – Emond Apr 29 '15 at 10:55
  • 1
    It sounds like it would be easiest to keep your radio button group and style them to look like buttons. – James Lucas Apr 29 '15 at 10:59
  • 4
    If this is WinForms, the radio button has an `Appearance` property you can set to `Button`. Then you can style the `checked` appearance using `FlatAppearance`. – DonBoitnott Apr 29 '15 at 10:59
  • @sandwich_messiah i havent coded anything for this so far, i was just wondering if it was possible to do this without creating a lengthy method to deselect the currently selected button and select the new button – Dean Lewis Apr 29 '15 at 10:59
  • Radiobuttons are already set up (at least in WinForms as far as I'm aware) to have only 1 selected at a time on the form, assuming you haven't placed them in different `groupBoxes`, unless you otherwise specify. – EyeSeeSharp Apr 29 '15 at 11:01
  • @DionV. I haven't tried any coding on this part yet – Dean Lewis Apr 29 '15 at 11:01
  • @JamesLucas I just want the background colour to change on the button, and when it is selected the value assosciated with that button will be stored in a variable, i dont want to use radio buttons as they will not go with the design of the interface – Dean Lewis Apr 29 '15 at 11:02
  • @JamesLucas I wasn't aware I could re-style radio buttons to look like normal buttons, Sorry, I will look into doing that, Thanks for the help! – Dean Lewis Apr 29 '15 at 11:03

1 Answers1

1

This approach uses Toggle buttons in a list box and uses selected item binding to managed which one is toggled. This will maintain the button look and add radio button behavior:

How to get a group of toggle buttons to act like radio buttons in WPF?

Community
  • 1
  • 1
James Lucas
  • 2,452
  • 10
  • 15