开发者

looking for how to make my own MessageBox sample code

looking for how to make开发者_如何学编程 my own MessageBox sample code

something simple that has title, body text and yes/no button

and how to use it

thanks in advance


There is a built-in method for this. It will automatically display a message box on screen with your specified parameters. For example, the following line of code:

MessageBox.Show("Your body text goes here.",
                "Message Title",
                MessageBoxButtons.YesNo);

will produce a message box that looks like this:

   

looking for how to make my own MessageBox sample code


You can also specify an icon for your message box using a different overload of the MessageBox.Show function. For example:

MessageBox.Show("Your body text goes here.",
                "Message Title",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Warning);

The complete list of icon values is available here.


The return value of the MessageBox.Show function is a DialogResult value corresponding to the button that was clicked on the message box. By checking the return value, you can determine which course of action was chosen by the user. For example:

private void QueryExitApplication()
{
    // Show a message box, asking the user to confirm that they want to quit
    DialogResult result;
    result = MessageBox.Show("Do you really want to quit this application?",
                             "Quit Application?",
                             MessageBoxButtons.YesNo,
                             MessageBoxIcon.Warning);

    // Check the returned value of the MessageBox.Show function
    // (this corresponds to the button clicked by the user)
    if (result == DialogResult.Yes)
    {
        // Close the form
        this.Close();
    }

    // Otherwise, they selected No (so do nothing)
}


You can create custom dialog boxes as given here:

http://www.codeproject.com/KB/cs/A_Custom_Message_Box.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜