Radio Buttons in Menu

  • Thread starter Thread starter Martijn Mulder
  • Start date Start date
M

Martijn Mulder

How can I put a set of Radio Buttons in a Menu? A bullet list of items where
selecting one automatically unselects the others.

Thanks
 
Hi,

This functionality is not automatic. (Assuming you are referring to VS
2003, .NET 1.1)

Might be many ways to do it. Manually or Cleverly...

Here's my way : (The manual way)

--------------------------------------------

// This method is wired to Click events of all the MenuItems.
private void AllMnus_Click(object sender, System.EventArgs e)
{
MenuItem mnu = (MenuItem)sender;
Checker(mnu);
switch (mnu.Text)
{
case "One":
// Do your stuff
break;
case "Two":
// Do double the stuff
break;
case "Three":
// Do double the stuff
break;
}
}

// Iterates through the MenuItems, first unchecking all of them, and
then checking
// the relevant one.
private void Checker(MenuItem mnu)
{
foreach (MenuItem eachMnu in mnuTest.MenuItems)
{
eachMnu.Checked = false;
}
mnu.Checked = true;
}

--------------------------------------------

Explanation : Since the MenuItems have no Tag property (and
surprisingly, no Name property as well), we have to check the Text
property to find out which one was clicked. Then we just uncheck all of
them and check the proper one.

The Clever way :
An excellent alternative to doing it manually, might be to use Mick
Doherty's implementation. He uses an Extender component to add a Tag
property to MenuItems, and also a RadioGroup property which
accomplishes what we need. He should call it "Killing two birds with
one stone !" ;-)

This latter is the method I would recommend to you. Check out
<http://www.dotnetrix.pwp.blueyonder.co.uk/menus.html>

Regards,

Cerebrus.
 
You can use Checked menus..and use code to do the check/uncheck. Why radio
buttons? any reason?

VJ
 
I think Martijn means a RadioCheck style of Checked Menus. Not a Radio
button control. Atleast, that's what I assumed.

Regards,

Cerebrus.
 
I think Martijn means a RadioCheck style of Checked Menus. Not a Radio
button control. Atleast, that's what I assumed.


Radio Buttons

A radio button looks very much like a check box except that it is shaped
like a circle rather than a box. A heavy dot within the circle indicates
that the radio button has been checked. The radio button has the window
style BS_RADIOBUTTON or BS_AUTORADIOBUTTON (...). groups of radio buttons
are conventionally used to indicate mutually exclusive options. Unlike check
boxes, radio buttons do not work as toggles - that is, when you click a
radio button a second time, its state remains unchanged. (Petzold,
Programming Windows 95)

I want to have a dropdown menu from the main menu filled with radio buttons,
like this:

File Edit View Options
o Black/White
o Color
o Sepia
o Acid

with one of the options on and all other options off until clicked.
 
Hi,

Did you see my response to your original post ?? It still sounds like
that's what you need.

Regards,

Cerebrus.
 
Did you see my response to your original post ?? It still sounds like
that's what you need.

I am afraid you are right (thank you!). It's just that I expected it to be
build into C# and that it was only naming confusion that stopped me from
finding it. The System.Windows.Forms.ToolStripMenuItem does have a way to
set CheckBoxes on them, the square boxes that you can click on/of. The
Radiostyle that I need is not supported? mhhh...
 
Then the difference is not in language, but in the version of VS. I'm
still at VS 2003.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top