472,119 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

Can I get handle of parent MDI form?

If FormMain = MDI parent, FormSub = Child parent,
I execute FormSub from the menu like this way.

FormSub^ sub = gcnew FormSub;
sub->MdiParent = this;
sub->Show();

This can generate child form sub in FormMain.
In th FormMain, there is status bar label named statusBar;
I'd like to add code in the sub form that can access statusBar of parent
form.

I thought I can access to parent form member function in the sub form
like this way,
(This worked in VB.NET)
this->MdiParent->statusBar->Text = "sub closed!!!";
But this->MdiParent doesn't show me statusBar.
this->ParentForm doesn't work, too.
I made status bar label public in the MainForm, it doesn't work, too.

Is there any other way I can try?

Thanks.

Dec 14 '05 #1
3 2539
You must cast this->MdiParent to the MdiParent form class (FormMain)
--
Un saludo
Rodrigo Corral Gonzalez [MVP]

FAQ de microsoft.public.es.vc++
http://rcorral.mvps.org
Dec 14 '05 #2
Thanks for your answer Mr. Corral.

Here comes another problem.

in Parent.h

public ref class Parent : public System::Windows::Forms::Form {
public:
Parent {
...
}
....

in Project.cpp

#include "stdafx.h"
#include "Child.h"
#include "Parent.h"
....

in Child.h

public ref class Child: : public System::Windows::Forms::Form {
public:
Child {
...
}
....
When I add a function in Parent class like

Child^ child = gcnew Child;
child->MdiParent = this;
child->Show();

I can use the all the functions of the child.
But when I tried to use parent form in the Child class like

Form^ parent = gcnew Form;
parent = this->MdiParent; // This should be Parent
parent->statusBar->Text = "Test"; // Error, not visible

Ok, as your comment, this should be

Parent^ parent = gcnew Parent;
parent = this->MdiParent;
parent->statusBar->Text = "Test";

But I can't do this. T_T
When the include file sequence is
#include "Child.h"
#include "Parent.h"
class Child can't see class Parent so the compiler's complaining "What's
the Parent, men?"
After changing the sequence, "What's the Child, men?"

Thanks for your comment and plz help me one more time.

Rodrigo Corral [MVP] wrote:
You must cast this->MdiParent to the MdiParent form class (FormMain)

Dec 15 '05 #3
You must do a forward class declaration.

http://www-subatech.in2p3.fr/~photon...PP-INC-1.shtml

You don¢¥t need do:

Parent^ parent = gcnew Parent;
parent = this->MdiParent;
parent->statusBar->Text = "Test";

Better:

Parent^ parent = this->MdiParent;
parent->statusBar->Text = "Test";
--
Un saludo
Rodrigo Corral Gonzalez [MVP]

FAQ de microsoft.public.es.vc++
http://rcorral.mvps.org


Dec 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Ayaz Ali | last post: by
3 posts views Thread by TC | last post: by
12 posts views Thread by Tom W | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.