简体   繁体   English

C#格式化MessageBox

[英]C# formatting a MessageBox

I want to display a MessageBox alerting the user that the process is complete, and giving a breakdown on how long each stage of the process took. 我想显示一个MessageBox,提醒用户该过程已完成,并详细说明该过程的每个阶段所花费的时间。 I've got the text that I want to display formatted appropriately, but the default font of the MessageBox class is not mono-width. 我有正确显示格式的文本,但MessageBox类的默认字体不是单宽度。 As far as I can tell, there's no way to specify the font that the text displays with. 据我所知,没有办法指定文本显示的字体。

Is there an out-of-the-box library somewhere that I can use for this, or am I going to have to write one up myself? 是否有一个开箱即用的库可供我使用,或者我将不得不自己写一个?

Any reason not to just create a Form with a textbox/label using a monospace font, then call Form.ShowDialog ? 有什么理由不使用等宽字体创建带有文本框/标签的Form ,然后调用Form.ShowDialog Sounds like a separate library with that would be overkill to me. 听起来像一个单独的图书馆对我来说太过分了。

For the record, this is in fact possible, MessageBox() expands tabs. 为了记录,这实际上是可能的,MessageBox()扩展了标签。 For example: 例如:

    private void button1_Click(object sender, EventArgs e) {
        MessageBox.Show(
            "hello\tworld\r\n" + 
            "second\tline");
    }

It isn't very trustworthy if the word width starts to approach the tab width. 如果单词宽度开始接近标签宽度,则不是很值得信赖。 You still should prefer a little helper form with a ListView. 你仍然应该选择一个带有ListView的小助手形式。

I have just written a single file replacement for MessageBox with a changeable font. 我刚刚使用可更改的字体为MessageBox编写了单个文件替换。 You can download it here and use it like a standard MessageBox: 您可以在此处下载并像标准MessageBox一样使用它:

http://www.codeproject.com/Articles/601900/FlexibleMessageBox-A-flexible-replacement-for-the http://www.codeproject.com/Articles/601900/FlexibleMessageBox-A-flexible-replacement-for-the

Regards, Jörg 此致,Jörg

听起来你可能只想在那里放一个新表格并使用一些标签..

I use this: 我用这个:

public void myMessageBox(object str)
{
    System.Windows.Forms.MessageBox.Show( new System.Windows.Forms.Form{ TopMost = true, Width = 300}, str.ToString() );
}

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

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