如何显示包含一些标签内容的MessageBox消息?

时间:2010-11-05 16:56:47

标签: c# winforms messagebox

我想让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);            
    }

4 个答案:

答案 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);