Windows Forms> How to Control Main_Form from Sub_Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I am developing a project using Windows Forms .NET by using Visual C++ .NET
v2003.
I open a Sub_Form by clicking a button on the Main_Form. Some operations are
working at Main_Form and results of those works are updating the texts and
enable statuses of controls (LabelBox, Buttons, etc.) on the Sub_Form.
I would like to control and update the controls' text, enabled statuses at
Main_Form from Sub_Form.
Let's say my initial form is MDI type (Main_Form). It has a StatusBar and
StatusBarPanels. I open a child form (Sub_Form) by clicking menu option.
Whenever I click a button on Sub_Form, I want to inform the user by changing
the text of a StatusBarPanel on Main_Form (MDI Parent).
I thank your kind guidance in advance.
--
~~~~~~~~~~~~~~~~~~~
İyi Çalışmalar
Alper AKÇAYÖZ (Bil Muh)

Wish You Good Work
Alper AKCAYOZ (Bil Muh)
 
Add a 'Parent' property/member to Sub_Form that is set through its
constructor. Then just use the 'this' keyword as the constructor's parameter.
 
I think an overloaded constructor, which takes the address of Main_Form as
parameter, should be in the class of Sub_Form. Like below;

SUB_FORM.H
------------------------
#include "Main_Form.h"
....
public __gc class MDI_Child : public System::Windows::Forms::Form
{
...
public:
void Sub_Form(void)
{
InitializeComponent();
}

public:
System::Windows::Forms::Form *frmMain;

//If I state Main_Form as type of a variable, compiler gives error
//How can I include the Main_Form class into Sub_Form ???
void Sub_Form( Main_Form *frm )
{
frmMain = frm;
InitializeComponent();
}
...
}

How can I include the Main_Form class into Sub_Form ?
 
Back
Top