T.K.
T.K.

Reputation: 2259

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. I've got the text that I want to display formatted appropriately, but the default font of the MessageBox class is not mono-width. 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?

Upvotes: 12

Views: 28884

Answers (5)

T.Todua
T.Todua

Reputation: 56341

I use this:

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

Upvotes: -1

jreichert
jreichert

Reputation: 1566

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

Upvotes: 4

Hans Passant
Hans Passant

Reputation: 941257

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.

Upvotes: 11

Jon Skeet
Jon Skeet

Reputation: 1499730

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.

Upvotes: 17

Lynn Crumbling
Lynn Crumbling

Reputation: 13357

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

Upvotes: 2

Related Questions