我想让messagebox.show说(“抱歉 - 你输了,数字是”,“label1.Text”);但是它说label.text我希望它说出生成的数字。
private void button1_Click(object sender, EventArgs e)
{
RandomNumber(0,99);
button2.Enabled = true ;
button1.Enabled = false;
if (textBox1.Text == label1.Text)
MessageBox.Show("Winner");
if (textBox1.Text != label1.Text)
MessageBox.Show("Sorry - You Lose, The number is{0}",label1.Text);
}
答案 0 :(得分:2)
MessageBox.Show(string.Format("Sorry - You Lose, The number is {0}",label1.Text));
答案 1 :(得分:2)
MessageBox.Show(string.Format("Sorry - You Lose, The number is{0}",label1.Text));
答案 2 :(得分:2)
将String.Format添加到您对MessageBox.Show的调用....这是您的代码,模式显示我的意思。
private void button1_Click(object sender, EventArgs e)
{
RandomNumber(0,99);
button2.Enabled = true ;
button1.Enabled = false;
if (textBox1.Text == label1.Text)
MessageBox.Show("Winner");
if (textBox1.Text != label1.Text)
MessageBox.Show( String.Format("Sorry - You Lose, The number is{0}",label1.Text));
}
答案 3 :(得分:1)
MessageBox.Show("Sorry - You Lose, The number is " + label1.Text);