Paul
Paul

Reputation: 347

c++CLI event handler's not triggered

I am just getting into c++ CLI and am running into a problem where some event handlers are called and some are not.

here is a list of my event handlers:

    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
             }
    private: System::Void exitToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
                 Application::Exit();
             }
private: System::Void aboutToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
             MessageBox::Show("Paul Madsen\nLab 13",
                 "About lab 13", MessageBoxButtons::OK,
                 MessageBoxIcon::Asterisk);
         }

private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) 
         {
             try
             {
                double tmp = Double::Parse(textBox1->Text);
             }
             catch(...)
             {
                 textBox1->ResetText();
             }

         }
private: System::Void textBox2_TextChanged(System::Object^  sender, System::EventArgs^  e) 
         {
             try
             {
                double tmp = Double::Parse(textBox2->Text);
             }
             catch(...)
             {
                 textBox2->ResetText();
             }
         }
private: System::Void textBox1_Enter(System::Object^  sender, System::EventArgs^  e)
         {
             MessageBox::Show("Test",
                 "test", MessageBoxButtons::OK,
                 MessageBoxIcon::Asterisk);
         }
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
             double tmp = (Double::Parse(textBox1->Text) - 32) * 5/9;
             textBox2->Text = System::Convert::ToString(tmp);

         }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
              double tmp = (Double::Parse(textBox1->Text) - 32) * 5/9;
              textBox1->Text = System::Convert::ToString(tmp);

          }

button1_Click works just fine but button2_Click is never triggered even though they are essentially the same. Why is that?

Upvotes: 1

Views: 388

Answers (1)

Hans Passant
Hans Passant

Reputation: 941525

Look back toward the beginning of the source code file, inside InitializeComponent(). You should have no trouble seeing the button1->Click event handler assignment. Do you see the one for button2->Click?

Delete the button in the designer, add it back. Double click it. Or just leave it out, no point in having two buttons doing the same thing.

Upvotes: 1

Related Questions