MDI parent and child communication...??

M

Maheshkumar.R

Hi groups,
How i can command over the MDI CHIlD forms created dynamically at runtime from PARENT.

Let say, i have generated 5 mdichild forms, but i want to work with child form1 from MDI parent menu functions. if i select draw line in MDI parent, the line should be drawn in current active child..any URLS for this or guide me to achieve this communication...

--
Mähésh Kumär. R





http://spaces.msn.com/members/cyberiafreak
 
G

Guest

Hi

Are the child forms all of the same type, or are they of different types

Kind regards

Ronnie
 
M

Maheshkumar.R

All forms are same type....loaded with an activeX component in that child
form.


let me give my scenario, thru MDI parent i 'm selectin 3 raw images from the
File_open dialog of MDIParent. For displaying this images I'm creating
objects of a child form with activex defined in it.

so my mdichild component should recieve the filename from MDI parent and
also i want to play with that MDichild(loaded with activex) from the menu;s
provided in MDI parent form..


MDI parent ->>> events, functions ---->> MDI child (which is active)


How i can communicate this form...?

Thnks for your reply...

Mahes




Ronnie Edgar said:
Hi

Are the child forms all of the same type, or are they of different types

Kind regards

Ronnie
child form1 from MDI parent menu functions. if i select draw line in MDI
parent, the line should be drawn in current active child..any URLS for this
or guide me to achieve this communication...
 
G

Guest

Hi

I will supply some sample code...

create a test app, with two forms, and cut and paste the following code into
the forms replacing all of the existing code..

what is illustrated is that a parent carries a reference to its active
child, and the child carries a reference to its parent, therefore when that
form becomes active the parents active child can be set.

Form1

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace MDI_Test
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.Text = "Say Hello";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(448, 406);
this.IsMdiContainer = true;
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;

private Form2 m_fCurrent;

public Form2 fCurrent
{
get
{
return m_fCurrent;
}
set
{
m_fCurrent = value;
}
}

private void Form1_Load(object sender, System.EventArgs e)
{
Form2 f2 = new Form2();

f2.MdiParent = this;
f2.Show();
f2.f1 = this;
f2.Text = "Bill";

Form2 f3 = new Form2();

f3.MdiParent = this;
f3.Show();
f3.f1 = this;
f3.Text = "Mary";


}

private void menuItem1_Click(object sender, System.EventArgs e)
{
fCurrent.SayHello();
}
}
}


Form 2

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace MDI_Test
{
/// <summary>
/// Summary description for Form2.
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form2()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form2";
this.Text = "Form2";
this.Load += new System.EventHandler(this.Form2_Load);
this.Enter += new System.EventHandler(this.Form2_Enter);

}
#endregion

private Form1 m_f1;

public Form1 f1
{
get
{
return m_f1;
}
set
{
m_f1 = value;
}
}


private void Form2_Load(object sender, System.EventArgs e)
{

}

private void Form2_Enter(object sender, System.EventArgs e)
{
this.f1.fCurrent = this;
this.f1.Text = this.f1.fCurrent.Text;
}

public void SayHello()
{
MessageBox.Show("Hello I am a - " + this.Name + " My Name Is " +
this.Text);
}
}
}


//end of code

what this demonstrates is the creation of two forms of the same type, and
calling the method sayhello() on the active form.

remember and switch the active forms before trying the menu option, or there
is no active child set...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top