简体   繁体   English

是否有一条类似水平线的东西(即 <hr> )可以用于C#消息框?

[英]Is there something like a horizontal line (i.e. <hr>) that can be used for C# Message Box?

For example instead of doing the ("\\n-----------------"); 例如,而不是执行("\\n-----------------"); for a MessageBox.Show(); 用于MessageBox.Show(); function, is there an in-build horizontal line generator similar to the HTML <hr> ? 函数,是否有类似于HTML <hr>的内置水平线生成器?

A messagebox is a simple element for showing plain text. 消息框是用于显示纯文本的简单元素。 It does not have much design features. 它没有太多的设计功能。

However you can easily create a new form, put in its text and show it using Form.ShowDialog . 但是,您可以轻松创建一个新表单,将其文本放入并使用Form.ShowDialog显示它。 Now you can add any design-element you want by chosing it in the toolbox, eg by using a 2px label as shown here . 现在,您可以通过在工具箱中选择所需的任何设计元素来添加它,例如,使用2px标签,如此处所示

You could also implement the syntax you know from MessageBox by using a static method: 您还可以使用静态方法来实现从MessageBox知道的语法:

public class CustomMessageBox : Form
{
    private readonly static instance = new CustomMessageBox();
    private DialogResult result = DialogResult.No;

    private CustomMessageBox()
    {
        btnOK.DialogResult = DialogResult.OK;
        btnCancel.DialogResult = DialogResult.Cancel;
        this.AcceptButton = btnOK;
        this.CancelButton = btnCancel;
    }
    public static DialogResult Show(string text)
    {
        return instance.ShowDialog();
    }
}

Create a form, and send the message in your constructor or in function. 创建一个表单,然后在构造函数或函数中发送消息。 And set the available buttons that you want to see... That way you can handle the response-buttons 并设置您要查看的可用按钮...这样您就可以处理响应按钮

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM