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,等等。
祝你好运