【问题标题】:Eventhandlers between different forms (parent/child)不同表单(父/子)之间的事件处理程序
【发布时间】:2016-03-15 05:44:47
【问题描述】:

我对 c++ 很陌生,到目前为止,我在理解基础知识方面有点困难。我现在有 2 个表格。

父.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");
  }
}

我基本上希望父母在孩子有事件时做一些事情,在这种情况下,只是一个负载。它编译并且不给出警告/错误,子执行事件,但它从不触发父事件。 想要这样做是为了能够在父母和孩子之间进行互动,到目前为止,我在这样做时遇到了很多麻烦。

【问题讨论】:

    标签: forms c++-cli parent-child eventhandler


    【解决方案1】:

    明确地说,您是否希望 parent 对孩子的“加载”事件做出反应?

    如果是这样,那么您链接的事件不正确。你的代码:

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

    将 Load 事件处理程序链接到 v_child 而不是 parent。试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-18
      • 1970-01-01
      • 2015-04-14
      • 2017-05-09
      • 2017-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多