-6
private void textBox1_TextChanged(object sender, EventArgs e)
{
    if (a.Equals(b))
    {
        result = a.ToString();
        textBox1.Text = result;
        textBox1.TextAlign = HorizontalAlignment.Left;
    }
    else
        result = b.ToString();
    textBox1.Text = result;
    textBox1.TextAlign = HorizontalAlignment.Center;
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
afsun shah
  • 11
  • 1
  • 6
    What exactly are you are having problems with? What's currently not working with your if statements? – ryanyuyu Jan 23 '15 at 15:01
  • Are you missing brackets for the else or is that intentional? – Thijs Jan 23 '15 at 15:02
  • @Plue [that edit](http://stackoverflow.com/review/suggested-edits/6829258) is invalid. Don't change the code of a question, especially since the missing brackets may be the source of the issue. – CodeCaster Jan 23 '15 at 15:03
  • 1
    @CodeCaster sorry I thought I deleted it myself while editing – Plue Jan 23 '15 at 15:06

1 Answers1

0

Most probably you forgot to add brackets in your else statement.

Try this code:

private void textBox1_TextChanged(object sender, EventArgs e)
{
    if (a.Equals(b))
    {
        result = a.ToString();
        textBox1.Text = result;
        textBox1.TextAlign = HorizontalAlignment.Left;
    }
    else
    {
        result = b.ToString();
        textBox1.Text = result;
        textBox1.TextAlign = HorizontalAlignment.Center;
    }
}

It is always good practice to place curly brackets in if, else statements, loops, etc.

Read answers in this question: Why is it considered a bad practice to omit curly braces?

Community
  • 1
  • 1
Nikolay Kostov
  • 16,433
  • 23
  • 85
  • 123