Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何从子窗体C++。网_C++_.net_Forms_Parent Child_Mdiparent - Fatal编程技术网

C++ 如何从子窗体C++。网

C++ 如何从子窗体C++。网,c++,.net,forms,parent-child,mdiparent,C++,.net,Forms,Parent Child,Mdiparent,我需要在C++.NET中的Child表单中将ToolStripMenuItem置于Enabled上。我尝试在互联网上搜索,但没有什么C++,所有的答案都是C语言的。< /P> 我尝试了这一点,但不起作用(菜单_open是ToolStripMenuItem): 我尝试: (Form1)this->MdiParent->Controls["menu_open"]->Enabled=true; 及 但是找不到父级的Form1。请帮忙 我尝试这样做:添加行 ref class For

我需要在
C++.NET
中的
Child
表单中将
ToolStripMenuItem
置于
Enabled
上。我尝试在互联网上搜索,但没有什么C++,所有的答案都是C语言的。< /P> 我尝试了这一点,但不起作用(
菜单_open
ToolStripMenuItem
):

我尝试:

(Form1)this->MdiParent->Controls["menu_open"]->Enabled=true;

但是找不到父级的
Form1
。请帮忙

我尝试这样做:添加行

ref class Form1;
 Form1^ parent;
在子窗体和行的命名空间内

ref class Form1;
 Form1^ parent;
public ref类子类的内部
。现在我有一个父窗体的对象,我尝试:

parent->Controls["menu_open"]->Enabled = true;
但我有一个错误:

   use of undefined type 'DataLogger::Form1'
   left of '->Controls' must point to class/struct/union/generic type
   left of '->Enabled' must point to class/struct/union/generic type
   use of undefined type 'DataLogger::Form1'       
   left of '->Controls' must point to class/struct/union/generic type
   left of '->Enabled' must point to class/struct/union/generic type

如果有人会有同样的问题,我找到了答案。您需要使用父窗体的
mdichildactive
事件。当创建子项且cild关闭时,将出现此事件。要解决此问题,请使用以下代码:

closeChild++;
String ^ childName = this->MdiChildren[0]->Text;

if(closeChild == 2)
   menu_open->Enabled=true;
在0上的函数集之外创建专用变量:

private: static int closeChild = 0;
private:System::Void Form1\u MdiChildActivate(System::Object^sender,System::EventArgs^e)
中,使用以下代码:

closeChild++;
String ^ childName = this->MdiChildren[0]->Text;

if(closeChild == 2)
   menu_open->Enabled=true;
closeChild
在关闭时将为2并且在创建新的子项时不要忘记将
closeChild
重置为0,因为
closeChild
将增加到3,等等。

祝你好运