Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a MessageBox message containing some label content?

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)
            MessageBox.Show("Winner");
        if (textBox1.Text != label1.Text)
            MessageBox.Show("Sorry - You Lose, The number is{0}",label1.Text);            
    }
like image 798
user770022 Avatar asked Feb 25 '23 21:02

user770022


2 Answers

MessageBox.Show("Sorry - You Lose, The number is " + label1.Text);
like image 142
mint Avatar answered Apr 30 '23 11:04

mint


MessageBox.Show(string.Format("Sorry - You Lose, The number is {0}",label1.Text));
like image 43
Jakub Konecki Avatar answered Apr 30 '23 12:04

Jakub Konecki