如在VC++.NET 2003 Test托管程序中,有两Form1 和Form2,Form1为父窗体,Form2为子窗体.
Form1中引用#include "Form2.h"头文件
private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e)
{
Test::Form2 * form2 = new Test::Form2();
form2->MdiParent = this;
form2->Show();
}Form2中引用#include "Form1.h"头文件
private: System::Void Form2_Load(System::Object * sender, System::EventArgs * e)
{
Test::Form1 * form1 ;
form1 = dynamic_cast<Test::Form1 *>(this->MdiParent);
form1->Text = "AAA";
}
这样写为什么会出错?该怎样实现父子窗体之间相互调用?
Form1中引用#include "Form2.h"头文件
private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e)
{
Test::Form2 * form2 = new Test::Form2();
form2->MdiParent = this;
form2->Show();
}Form2中引用#include "Form1.h"头文件
private: System::Void Form2_Load(System::Object * sender, System::EventArgs * e)
{
Test::Form1 * form1 ;
form1 = dynamic_cast<Test::Form1 *>(this->MdiParent);
form1->Text = "AAA";
}
这样写为什么会出错?该怎样实现父子窗体之间相互调用?
解决方案 »
- C#中在DataGridView中添加一行数据后,怎样让该行被选中?
- 1急求!编写一个程序,对于给定的一个字符串的集合,要求将其中交集不为空的集合合并,要求合并完成后的集合之间无交集
- 寻求好书
- GridView问题,如果其中的AnswerE为空RadioButton5怎样让他不显示。
- DataGridView 的DataBinding 问题
- .net IDE开发---------怎样新增主菜单
- 帮忙解释一下在global.asax中的几条语句!在线立结
- 请问一下这段代码是什么意思啊!很菜鸟的问题
- 如何将值写入到特定网页的某个文本框中?
- 哪儿有开发Web程序的实例,请大家告诉一声儿!
- 菜鸟请教,有关使用HTTP协议下载
- 关于考勤管理系统的一个问题,请高手赐教
this->MdiParent->Text = "AAA";
下面的代码不要,就出错,报FORM1不是TEST成员
form1 = dynamic_cast<Test::Form1 *>(this->MdiParent);
form1->Text = "AAA";
this->MdiParent->Text = "AAA";
(Test::Form1 * )(this->MdiParent)
Test::Form1 * form1 ;
子窗体如下:
public __delegate void SetTextValueHandler( char* sValue );
/// <summary>
/// Summary for frmChild
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public __gc class frmChild : public System::Windows::Forms::Form
{
public:
frmChild(SetTextValueHandler * Handler)
{
InitializeComponent();
mHandler = Handler;
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container* components;
SetTextValueHandler* mHandler; /// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
//
// frmChild
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(292, 273);
this->Name = S"frmChild";
this->Text = S"frmChild";
this->Load += new System::EventHandler(this, frmChild_Load); }
private: System::Void frmChild_Load(System::Object * sender, System::EventArgs * e)
{
this->mHandler( "AAA" );
}
};
private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e)
{
frmChild * myChild = new frmChild(
new SetTextValueHandler( this, &Form1::SetTextValue) );
myChild->MdiParent = this;
myChild->Show();
} void SetTextValue( char* sValue )
{
this->Text = sValue;
}