I would like for the messagebox.show to say ("Sorry - You Lose, The number is","label1.Text"); but where it says label.text I want it to say the number that was generated.
private void button1_Click(object sender, EventArgs e)
{
RandomNumber(0,99);
button2.Enabled = true ;
button1.Enabled = false;
if (textBox1.Text == label1.Text)
开发者_如何学Python MessageBox.Show("Winner");
if (textBox1.Text != label1.Text)
MessageBox.Show("Sorry - You Lose, The number is{0}",label1.Text);
}
MessageBox.Show("Sorry - You Lose, The number is " + label1.Text);
MessageBox.Show(string.Format("Sorry - You Lose, The number is {0}",label1.Text));
MessageBox.Show(string.Format("Sorry - You Lose, The number is{0}",label1.Text));
Add String.Format to your call to MessageBox.Show.... Here is your code, moded to show what i mean.
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));
}
精彩评论