Change Mdi property from child form

K

kjqua

Dear all,
I having hard time :) with Mdi forms.

Let me explain my problem by point

(1) I have a Mdi Form called frm_Main
frm_main have a MenuStrip called menuStrip1

(2) then i have a child form called frm_pippo
frm_pippo is called inside frm_main

(3) I would like to enable or disable the Menustrip control from
frm_pippo

// Thi is the code that i try to use inside the frm_pippo
((frm_main)Parent.Parent.Controls["menuStrip1"]).Enabled = false;

:( but it don't work, some idea ?

Thanks a lot
 
D

DaveL

in your Main Window make sure IsMidiContainer Set To True

when opening Child Window
set MidiParent=this
// so when you open your Child Window
the Parent (midi) window is visible , you then
this.MidiParent.ToolStrip1.Enabled=false;
be sure to set the Menustrip modifier to public
Also you can set the Parent Menustrip to disable
in the Event that opens the Child

or have a method in the parent Window to manage the disable/enable since you
might have multiple windows disable or enableing the menu


DaveL
 
J

Jeff Johnson

I having hard time :) with Mdi forms.

Let me explain my problem by point

(1) I have a Mdi Form called frm_Main
frm_main have a MenuStrip called menuStrip1

(2) then i have a child form called frm_pippo
frm_pippo is called inside frm_main

(3) I would like to enable or disable the Menustrip control from
frm_pippo

// Thi is the code that i try to use inside the frm_pippo
((frm_main)Parent.Parent.Controls["menuStrip1"]).Enabled = false;

:( but it don't work, some idea ?

Don't try to control the parent directly; just "talk to it."

Create an event in your MDI child. When you load that form from the MDI
parent, have the parent subscribe to the event. Then you raise the event in
the child passing a Boolean to tell the parent whether the menu should be
enabled or disabled. Then, in the parent's event handler, it can perform the
action based on the value provided by the child.

Something like this [Framework 2.0 compatible at least]:

[In some .cs file (doesn't really matter which)]
public class BooleanEventArgs : EventArgs
{
private bool _flag;
public bool Flag
{
get { return _flag; }
set { _flag = value; }
}

public BooleanEventArgs(bool flag)
{
_flag = flag;
}
}


[in MDI Child form]
public event EventHandler<BooleanEventArgs> MenuStatusChangeRequested;


// Whenever you want to enable/disable the menu you call this method with
the desired status
private void OnMenuStatusChange(bool status)
{
EventHandler<BooleanEventArgs> threadSafeCopy =
MenuStatusChangeRequested;

if (threadSafeCopy != null)
{
threadSafeCopy(this, new BooleanEventArgs(status));
}
}


[in MDI parent]
// This is the event handler you will attach to the child form
private void pippo_MenuStatusChangeRequested(object sender, BooleanEventArgs
e)
{
menuStrip1.Enabled = e.Flag;
}


[I typed this directly into this post, so there was no Intellisense to catch
typos. Hopefully if something doesn't work you can fix it easily....]
 
K

kjqua

DaveL thanks,

I try you suggestion but it do not work

But with the following code it work

i set Menustrip modifier to public in the MainForm MDI

private void Frm_mainLoad(object sender, EventArgs e)
{
this.menuStrip1.Enabled = false;

frm_Child Child = new frm_Child ();
Child .MdiParent = this;

Child .Show();
}

void Button1_inChild _Click(object sender, EventArgs e)
{
this.MdiParent.Controls["menuStrip1"].Enabled = true;
}


some other suggestions ?



in your Main Window make sure IsMidiContainer Set To True

when opening Child Window
set MidiParent=this
// so when you open your Child Window
the Parent (midi) window is visible , you then
this.MidiParent.ToolStrip1.Enabled=false;
be sure to set the Menustrip modifier to public
Also you can set the Parent Menustrip to disable
in the Event that opens the Child

or have a method in the parent Window to manage the disable/enable since you
might have multiple windows disable or enableing the menu

DaveL


Dear all,
I having hard time :) with Mdi forms.
Let me explain my problem  by point
(1) I have a Mdi Form called frm_Main
   frm_main have a MenuStrip called  menuStrip1
(2) then i have a child form called frm_pippo
   frm_pippo is called inside frm_main
(3) I would like to enable or disable the Menustrip control from
frm_pippo
// Thi is the code that i try to use inside the frm_pippo
((frm_main)Parent.Parent.Controls["menuStrip1"]).Enabled = false;
:( but it don't work, some idea ?
Thanks a lot
 
A

Ambitos

Hello Kjqua

Try this. It helps me

ParentForm.MainMenuStrip.Enabled = true;

MainMenuStrip is the menuStrim1 ( do not change name ).



Jeff Johnson said:
I having hard time :) with Mdi forms.

Let me explain my problem by point

(1) I have a Mdi Form called frm_Main
frm_main have a MenuStrip called menuStrip1

(2) then i have a child form called frm_pippo
frm_pippo is called inside frm_main

(3) I would like to enable or disable the Menustrip control from
frm_pippo

// Thi is the code that i try to use inside the frm_pippo
((frm_main)Parent.Parent.Controls["menuStrip1"]).Enabled = false;

:( but it don't work, some idea ?

Don't try to control the parent directly; just "talk to it."

Create an event in your MDI child. When you load that form from the MDI
parent, have the parent subscribe to the event. Then you raise the event in
the child passing a Boolean to tell the parent whether the menu should be
enabled or disabled. Then, in the parent's event handler, it can perform the
action based on the value provided by the child.

Something like this [Framework 2.0 compatible at least]:

[In some .cs file (doesn't really matter which)]
public class BooleanEventArgs : EventArgs
{
private bool _flag;
public bool Flag
{
get { return _flag; }
set { _flag = value; }
}

public BooleanEventArgs(bool flag)
{
_flag = flag;
}
}


[in MDI Child form]
public event EventHandler<BooleanEventArgs> MenuStatusChangeRequested;


// Whenever you want to enable/disable the menu you call this method with
the desired status
private void OnMenuStatusChange(bool status)
{
EventHandler<BooleanEventArgs> threadSafeCopy =
MenuStatusChangeRequested;

if (threadSafeCopy != null)
{
threadSafeCopy(this, new BooleanEventArgs(status));
}
}


[in MDI parent]
// This is the event handler you will attach to the child form
private void pippo_MenuStatusChangeRequested(object sender, BooleanEventArgs
e)
{
menuStrip1.Enabled = e.Flag;
}


[I typed this directly into this post, so there was no Intellisense to catch
typos. Hopefully if something doesn't work you can fix it easily....]
 

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