C# formatting a MessageBox

半世苍凉 提交于 2019-11-29 10:08:58

Any reason not to just create a Form with a textbox/label using a monospace font, then call 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. 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.

Sounds like you may just want to drop a new form in there and use a few labels..

I have just written a single file replacement for MessageBox with a changeable font. You can download it here and use it like a standard MessageBox:

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

Regards, 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() );
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!