开发者

How to show a MessageBox message containing some label content?

开发者 https://www.devze.com 2023-01-23 11:46 出处:网络
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.

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));            
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消