0

I am trying to display the message box as per the textbox i am getting the error, anybody please help on this :

namespace WindowsApplication7
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        this.label1.Text = textBox1.Text;
    }

    private void label1_TextChanged(object sender, EventArgs e)
    {
        if (int.Parse(label1.Text) >= 120)
        {
            MessageBox.Show("Dot Net Perls is awesome.",
    "Important Message");

        }
    }
 }
}
Mohammad
  • 1,549
  • 1
  • 15
  • 27
  • That means that the value of `label1` is not convertible to an integer, which the error message states. – VDWWD Jul 21 '18 at 12:30
  • Possible duplicate of [Input string was not in a correct format](https://stackoverflow.com/questions/8321514/input-string-was-not-in-a-correct-format) – VDWWD Jul 21 '18 at 12:32

1 Answers1

0

Try this :

        int value= 0;
        if (int.TryParse(textBox1.Text, out value))
        {
            if (value>= 120)
                MessageBox.Show("Dot Net Perls is awesome.",
                         "Important Message");
        }
Mohammad
  • 1,549
  • 1
  • 15
  • 27