2016-03-15 45 views
0

對於C++而言,我還是一個相當新的東西,至今我在理解基礎知識方面有點麻煩。我現在有兩種形式。不同形式(父/子)之間的事件處理程序

parent.h

#include "child.h" 
public ref class parent : public System::Windows::Forms::Form { 
    child^ v_child = gcnew child; 
    void InitializeComponent(void){ 
    v_child->Load += gcnew System::EventHandler(v_child, &child::child_Load); 
    } 
    private: System::Void child_Load(System::Object^ sender, System::EventArgs^ e) { 
    MessageBox::Show("Howdy"); 
    } 
} 

我基本上希望父母做一些事情,當孩子有一個事件,在這種情況下,只是一個負載。它編譯並且不給出警告/錯誤,孩子執行該事件,但它從不觸發父代。 想要做到這一點,以便能夠在父母和孩子之間進行互動,到目前爲止,我在這方面遇到了很多麻煩。

回答

0

要清楚,您是否想要parent對孩子的「加載」事件做出反應?

如果是這樣,那麼你錯誤地鏈接了事件。您的代碼:

v_child->Load += gcnew System::EventHandler(v_child, &child::child_Load); 

鏈接Load事件處理程序的v_childparent。試試這個:

v_child->Load += gcnew System::EventHandler(this, &parent::child_Load); 
相關問題