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! ;)

2 Answers 2

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");
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.