0

I would like to use a method, that creates a message box:

public class Layout
{
    public void MBox(string msgText, string msgCaption, MessageBoxButtons msgButton, MessageBoxIcon msgIcon)
    {
        MessageBox.Show(msgText, msgCaption, msgButton, msgIcon);
    }
}

Now, I try to open it by using the following code:

Layout _layout = new Layout();
_layout.MBox("Hello", "Hello again", OK, None);

Unfortunately, the application does not know "OK" and "None". What is my mistake? Could you please help me? Thanks in advance. Kind regards! ;)

Christoph Fink
  • 22,727
  • 9
  • 68
  • 113
sjantke
  • 605
  • 4
  • 9
  • 35

2 Answers2

2

You need to supply the type:

_layout.MBox("Hello", "Hello again", MessageBoxButtons.OK, MessageBoxIcon.None);

Additionally you could use default parameters to shorten the default case:

public void MBox(string msgText, string msgCaption, 
    MessageBoxButtons msgButton = MessageBoxButtons.OK, 
    MessageBoxIcon msgIcon = MessageBoxIcon.None)
{
    MessageBox.Show(msgText, msgCaption, msgButton, msgIcon);
}

The you can leave that two parameters out if they are Ok and None:

_layout.MBox("Hello", "Hello again");
Christoph Fink
  • 22,727
  • 9
  • 68
  • 113
1

You have to use MessageBoxButton.OK and MessageBoxIcon.None

MessageBoxButton is an enumeration of possible buttons to display in a messagebox. The same goes for MessageBoxIcon.

germi
  • 4,628
  • 1
  • 21
  • 38