Take the 2-minute tour ×

I would like for the input from textbox1.text to be displayed in the place holder {0} so that if textbox1.text = "Randy" I would like a messagebox to popup and say Firstname,Randy

MessageBox.Show("First Name,{0}", textBox1.Text);

What happens currently is a messagebox pops up and says First Name,{0}

share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

There's no overload that does formatted output for the MessageBox class. Use String.Format() to get your formatted string.

MessageBox.Show(String.Format("First Name,{0}", textBox1.Text));

To show a message box with a caption, use the MessageBox.Show(string, string) overload. First argument is the message while the second is the caption.

MessageBox.Show(String.Format("First Name,{0}", textBox1.Text), // message
                textBox1.Text); // caption (title)
share|improve this answer
Worked great thanks –  user770022 Nov 10 '10 at 4:42
How do I add a title to the messagebox using this way? –  user770022 Nov 10 '10 at 4:42
@randy: Refer to the different overloads for MessageBox.Show(). The one you're looking for is MessageBox.Show(string, string) –  Jeff Mercado Nov 10 '10 at 4:47
add comment

Your Answer


