views:

441

answers:

5

How can I produce a messagebox in a C# Win Forms application that displays a combobox with a series of values to select as well as the usual "Ok" button?

I would like to be able to trigger this on calling the MessageBox.Show() method. I am assuming some sort of override will be necessary, but I haven't seen any pre-existing examples for this.

+3  A: 

Use a custom Form instead with .showDialog()

thelost
+1  A: 

You can not. The Windows MessageBox has limited functionality. You can expose a similar looking window as Dialog, but if you use the MessageBox, you are limited to the functionality a MessageBox is having.

TomTom
A: 

If you want more than just OK(yes no cancel etc) try this link: http://msdn.microsoft.com/en-us/library/system.windows.forms.messageboxbuttons.aspx

here is an example on how to use it: http://msdn.microsoft.com/en-us/library/0x49kd7z.aspx

However if you want your own you will have to write it from the start. Create a new form and add constructors that take the parameters you need.

When your done just use

YourDialog dialog = new YourDialog("Button 1", "Button 2");
dialog.ShowDialog();
Oskar Kjellin
A: 

You'll need to create you're own form, here is a tutorial on how to do it, it's in VB.NET but it'll be simple enough to change to C#.

Fermin
A: 

If a message box is not enough, you may want to use a Task Dialog. If you must support Windows XP, you can't use the native API for that, but there are plenty of .NET implementations for both Windows Forms and WPF, and it's also quite easy to implement by yourself. The good thing is that users today are used to task dialogs, rather than custom message boxes.

OregonGhost