문제

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

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top