对话框。显示(“名字,{ 0 }”,textBox1.Text);

时间:2022-06-23 00:58:31

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

我想要textbox1的输入。文本显示在place holder{0}中,因此如果textbox1。我想要一个弹出框,然后说Firstname,Randy。

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

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

当前发生的是一个弹出的消息框{0}

1 个解决方案

#1


11  

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

不存在为MessageBox类格式化输出的重载。使用string. format()来获得格式化的字符串。

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。显示(字符串,字符串)过载。第一个参数是消息,第二个是标题。

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

#1


11  

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

不存在为MessageBox类格式化输出的重载。使用string. format()来获得格式化的字符串。

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。显示(字符串,字符串)过载。第一个参数是消息,第二个是标题。

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