简体   繁体   中英

Adding Radio Buttons on a MessageBox/DialogBox

Is it possible to add radio buttons on a msgbox/dialog message without creating a form like:

MessageBox.Show("Select Option", "Test", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

What I'm trying to achieve is that, with Yes/No Buttons I could add a radio buttons at the upper part of the message without creating a new winform/userform.

Let me know if this is achievable then if so please give me any good reference that might help achieve this stuffs.

As has been suggested, the simple solution is to create your own form and display it using the ShowModal method. It will work just like a MessageBox, but you can put any control you want on it.

You don't appear to be satisfied with that. In fact, there is a way to do this with a message box, but it is way too complicated. It involves installing a hook that will trigger when the message box is displayed, and then writing a bunch of code that will dynamically add controls and manipulate the layout of the message box. Which will have to be done with a bunch of P/Invoke because the message box is a native Win32 dialog, not a Windows Form. The wrapper classes won't be of any help. Really not worth it. Message boxes aren't designed to be extensible.

Consider using a Task Dialog instead. This is almost exactly what they are designed for. Instead of radio buttons, you use a series of command buttons that describe the choices that are available. This is a better UI because only a single click is required to make a choice, rather than two. It would look something like this:

"Do you want to save your work?" is called the Main Instruction and should be kept very short. Then there's a supplemental instruction underneath it that provides more details, if the user wants to read it. Finally, you have the series of command links that contain a brief and detailed description of what will happen when the user clicks them. In this case, "Save work" and "Don't save".

(The example is a dumb use of a Task Dialog. You should just use regular old buttons for Save/Don't Save. But it was the best example I could find on Google images.)

If you want, you can actually put radio buttons into a Task Dialog:

In fact, as that image shows, you can pretty much anything you want into a Task Dialog—way too much. It is very customizable. That is the big improvement it offers over the venerable old MessageBox API.

There is a .NET wrapper for the Task Dialog API available here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM