Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

winforms

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}

like image 281
user770022 Avatar asked Nov 10 '10 04:11

user770022


1 Answers

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)
like image 94
Jeff Mercado Avatar answered Oct 23 '22 15:10

Jeff Mercado