寻找如何制作我自己的 MessageBox 示例代码

发布于 2024-10-17 16:49:45 字数 89 浏览 3 评论 0原文

寻找如何使我自己的 MessageBox 示例代码变得

简单,包含标题、正文和是/否按钮

以及如何使用它,

提前致谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

差↓一点笑了 2024-10-24 16:49:45

有一个内置方法可以实现此目的。它将自动在屏幕上显示一个消息框,其中包含您指定的参数。例如,以下代码行:

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

将生成一个如下所示的消息框:

   

您还可以使用不同的重载为消息框指定图标MessageBox.Show函数。例如:

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

图标值的完整列表可在 此处获取

MessageBox.Show 函数的返回值是一个DialogResult 对应于在消息框中单击的按钮。通过检查返回值,您可以确定用户选择了哪个操作过程。例如:

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)
}

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:

   sample message box

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)
}
束缚m 2024-10-24 16:49:45

您可以创建自定义对话框,如下所示:

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

You can create custom dialog boxes as given here:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文