471,319 Members | 1,330 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

MDI child forms

I've created a simple MDI application and have designated the Window menu to
keep track of the mdi children. When I first load an mdi child, it's caption
consists of "File: no file loaded" and this is what appears on the Window
menu.

Now, after the mdi child loads, I call a method to load a specifically named
file. At this point, the child changes it's caption to reflect the new file
name. Unfortunately, the Window menu does not update and remains fixed on
"File: no file loaded".

Is there some trick I'm missing to ensure that the Window menu gets updated
to reflect the new child window caption?

Incidentally, I've found that this problem does not happen in the
development environment, but always happens on the compiled application.
Opening a second child window usually sorts the problem out.

I've tried invalidating the Window menu item and tried refreshing the
MenuStrip, but without any success.

Thanks
Steve

Dec 16 '05 #1
4 10823
There should be a .Parent or .MDIParent property on your
child form. Set its caption to your value.

myform.MDIParent.Caption = "blah"

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.eggheadcafe.com/forums/merit.asp

"Steve Barnett" <no****@nodomain.com> wrote in message
news:OE******************@tk2msftngp13.phx.gbl...
I've created a simple MDI application and have designated the Window menu
to keep track of the mdi children. When I first load an mdi child, it's
caption consists of "File: no file loaded" and this is what appears on the
Window menu.

Now, after the mdi child loads, I call a method to load a specifically
named file. At this point, the child changes it's caption to reflect the
new file name. Unfortunately, the Window menu does not update and remains
fixed on "File: no file loaded".

Is there some trick I'm missing to ensure that the Window menu gets
updated to reflect the new child window caption?

Incidentally, I've found that this problem does not happen in the
development environment, but always happens on the compiled application.
Opening a second child window usually sorts the problem out.

I've tried invalidating the Window menu item and tried refreshing the
MenuStrip, but without any success.

Thanks
Steve

Dec 16 '05 #2
Sorry, not sure how this helps. It's not the caption of the parent window
that's wrong, it's the name that appears on the WindowList menu. Even though
I have a file loaded and the child window caption has been changed, when I
open the Window menu, the WindowList shows the "original" caption that the
child window had before I changed it.

Steve
"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
There should be a .Parent or .MDIParent property on your
child form. Set its caption to your value.

myform.MDIParent.Caption = "blah"

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.eggheadcafe.com/forums/merit.asp

"Steve Barnett" <no****@nodomain.com> wrote in message
news:OE******************@tk2msftngp13.phx.gbl...
I've created a simple MDI application and have designated the Window menu
to keep track of the mdi children. When I first load an mdi child, it's
caption consists of "File: no file loaded" and this is what appears on
the Window menu.

Now, after the mdi child loads, I call a method to load a specifically
named file. At this point, the child changes it's caption to reflect the
new file name. Unfortunately, the Window menu does not update and remains
fixed on "File: no file loaded".

Is there some trick I'm missing to ensure that the Window menu gets
updated to reflect the new child window caption?

Incidentally, I've found that this problem does not happen in the
development environment, but always happens on the compiled application.
Opening a second child window usually sorts the problem out.

I've tried invalidating the Window menu item and tried refreshing the
MenuStrip, but without any success.

Thanks
Steve


Dec 16 '05 #3
Just in case anyone else struggles with this, I failed miserably to get the
window list managed for me automatically. In the end, I added a
DropDownOpening event handler in my MDI form load event:

MainMenu.MdiWindowListItem.DropDownOpening += new
EventHandler(this.UpdateWindowMenuList);

This causes the UpdateWindowMenuList method to run when I select the menu
assigned to contain the window list:

private void UpdateWindowMenuList(object sender, EventArgs e)
{
// The code to update the window list on the Window menu does not
appear
// to work - so I've cobbled this together.
Application.DoEvents();

foreach (ToolStripItem tsMenu in
MainMenu.MdiWindowListItem.DropDown.Items)
{
if (tsMenu is ToolStripMenuItem)
{
ToolStripMenuItem tsMenuItem = (ToolStripMenuItem)tsMenu;
if (tsMenuItem.IsMdiWindowListEntry)
{
// Work out the index of this form.
int iIndex = Int32.Parse(tsMenu.Text.Substring(1, 1)) - 1;

// Update the menu
tsMenuItem.Text = String.Format("&{0} {1}", iIndex + 1,
this.MdiChildren[iIndex].Text);
}
}
}
}

In this routine, I go look for each MDI child and adjust the caption in the
WindowList menu items.

It's probably not the best solution, but it seems to be working for me.

Steve
"Steve Barnett" <no****@nodomain.com> wrote in message
news:uf**************@TK2MSFTNGP14.phx.gbl...
Sorry, not sure how this helps. It's not the caption of the parent window
that's wrong, it's the name that appears on the WindowList menu. Even
though I have a file loaded and the child window caption has been changed,
when I open the Window menu, the WindowList shows the "original" caption
that the child window had before I changed it.

Steve
"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
There should be a .Parent or .MDIParent property on your
child form. Set its caption to your value.

myform.MDIParent.Caption = "blah"

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.eggheadcafe.com/forums/merit.asp

"Steve Barnett" <no****@nodomain.com> wrote in message
news:OE******************@tk2msftngp13.phx.gbl...
I've created a simple MDI application and have designated the Window
menu to keep track of the mdi children. When I first load an mdi child,
it's caption consists of "File: no file loaded" and this is what appears
on the Window menu.

Now, after the mdi child loads, I call a method to load a specifically
named file. At this point, the child changes it's caption to reflect the
new file name. Unfortunately, the Window menu does not update and
remains fixed on "File: no file loaded".

Is there some trick I'm missing to ensure that the Window menu gets
updated to reflect the new child window caption?

Incidentally, I've found that this problem does not happen in the
development environment, but always happens on the compiled application.
Opening a second child window usually sorts the problem out.

I've tried invalidating the Window menu item and tried refreshing the
MenuStrip, but without any success.

Thanks
Steve



Dec 19 '05 #4
Steve,

Ran into the same problem. Tried about everything and in the end used your
solution. I've modified the code such that there won't be a problem when
there are more than nine open mdichildren.

here it is:

Private Sub mnuDocuments_DropDownOpening(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles mnuDocuments.DropDownOpening

Dim Idx As Integer = -1

For Each M As ToolStripItem In
MainMenu.MdiWindowListItem.DropDown.Items
If TypeOf M Is ToolStripMenuItem Then
With CType(M, ToolStripMenuItem)
If .IsMdiWindowListEntry Then
Idx += 1
.Text = (Idx + 1).ToString("&0") & " " &
MdiChildren(Idx).Text
End If
End With
End If
Next

End Sub

I've also left out the Appication.DoEvents stuff. Seems to work without it.

Greetings.
Jan 6 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by James Spibey | last post: by
3 posts views Thread by Maheshkumar.R | last post: by
3 posts views Thread by Lance | last post: by
reply views Thread by Bruin | last post: by
2 posts views Thread by Lenster | last post: by
reply views Thread by Scott H. | last post: by
reply views Thread by emalcolm_FLA | last post: by
reply views Thread by rosydwin | 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.