2010-12-20 113 views
1

我剛剛進入C++ CLI,並遇到一些問題,其中一些事件處理程序被調用,有些不是。C++ CLI事件處理程序沒有被觸發

這裏是我的事件處理程序的列表:

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工作得很好,但button2_Click永遠不會觸發,即使它們在本質上是相同的。這是爲什麼?

回答

1

回頭看看InitializeComponent()中的源代碼文件的開頭。看到button1-> Click事件處理程序分配時,您應該沒有問題。你看到button2-> Click的一個嗎?

刪除設計器中的按鈕,將其添加回來。雙擊它。或者放棄它,沒有兩個按鈕做同樣的事情。

相關問題