MDI Repaint Problem

N

Nick

I'm creating an MDI application with multiple maximized
MDI child forms. When a child form is open, the
title/caption is merge with the MDI's title/caption. So,
if the MDI title is "Parent" and the 3rd MDI child
is "Child 3", then when the 3rd MDI child is opened, the
title becomes "Parent [Child 3]".

However, when child 3 is closed, the MDI title doesn't go
back to what it was before. It still says "Parent [Child
3]".

Is there anyway to force a refresh/repaint on the MDI
parent after a child has been closed?

Thanks.
Nick
 
M

Magnus Krisell

Nick said:
I'm creating an MDI application with multiple maximized
MDI child forms. When a child form is open, the
title/caption is merge with the MDI's title/caption. So,
if the MDI title is "Parent" and the 3rd MDI child
is "Child 3", then when the 3rd MDI child is opened, the
title becomes "Parent [Child 3]".

However, when child 3 is closed, the MDI title doesn't go
back to what it was before. It still says "Parent [Child
3]".

Is there anyway to force a refresh/repaint on the MDI
parent after a child has been closed?

Hi Nick,

I implemented this by handling the MdiChildActivate event of the parent
form and checking the ActiveMdiChild property. There may be a better
way, but at least it works.

- Magnus
 
N

Nick

Thanks for the response. Would you post some sample code,
please? I need the title to show "Parent - [Child 1]"
when child 1 is openned, and "Parent - [Child 2]" when
child 2 is openned. Then, when child 2 is closed, it
needs to go back to "Parent - [Child 1]". Currently, it
doesn't. It remains "Parent - [Child 2]".

Much Appreciated!
Nick
 
N

Nicholas Paldino [.NET/C# MVP]

Nick,

Basically, it looks like you want to set the title bar of the parent
whenever the child window gets focus. To do this, you will want to hook
into the Activate event for the child form. In the event handler, you just
get the MdiParent property for the form and set the Text property to what
you want.

Oh, and when creating the new child forms, make sure to set a property
indicating which child it is (you should have a factory that creates each
form, or have the constructor get the current number of MDI children).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Nick said:
Thanks for the response. Would you post some sample code,
please? I need the title to show "Parent - [Child 1]"
when child 1 is openned, and "Parent - [Child 2]" when
child 2 is openned. Then, when child 2 is closed, it
needs to go back to "Parent - [Child 1]". Currently, it
doesn't. It remains "Parent - [Child 2]".

Much Appreciated!
Nick
Hi Nick,

I implemented this by handling the MdiChildActivate event of the parent
form and checking the ActiveMdiChild property. There may be a better
way, but at least it works.

- Magnus


.
 
G

Guest

It seems strange that I should need to set the MDI form's
Text property because it looks like it's automatically
handling this (just handling it incorrectly). Is this a
bug with the .Net Framework?

I also noticed that after closing child 2, if I minimize
the program and maximize it again, the title corrects
itself and correctly displays "Parent - [Child 1]". I was
hoping I could just call the form.refresh method after
closing child 2. But that didn't work either.

Nick

-----Original Message-----
Nick,

Basically, it looks like you want to set the title bar of the parent
whenever the child window gets focus. To do this, you will want to hook
into the Activate event for the child form. In the event handler, you just
get the MdiParent property for the form and set the Text property to what
you want.

Oh, and when creating the new child forms, make sure to set a property
indicating which child it is (you should have a factory that creates each
form, or have the constructor get the current number of MDI children).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Thanks for the response. Would you post some sample code,
please? I need the title to show "Parent - [Child 1]"
when child 1 is openned, and "Parent - [Child 2]" when
child 2 is openned. Then, when child 2 is closed, it
needs to go back to "Parent - [Child 1]". Currently, it
doesn't. It remains "Parent - [Child 2]".

Much Appreciated!
Nick
Hi Nick,

I implemented this by handling the MdiChildActivate
event
of the parent
form and checking the ActiveMdiChild property. There may be a better
way, but at least it works.

- Magnus


.


.
 
M

Magnus Krisell

It seems strange that I should need to set the MDI form's
Text property because it looks like it's automatically
handling this (just handling it incorrectly). Is this a
bug with the .Net Framework?

I agree that it's strange, and I distinctly remember having this problem
myself a while back.

However, it seems that I am unable to reproduce it now. The following
code is a short but complete example that works correctly for me when
compiled with VS.NET 2003 and VS 2005 beta1. What version are you
using? I wonder if it might be a bug that exists in .NET Framework 1.0
(VS.NET 2002) but has been fixed in the later versions. I don't have
access to 1.0 right now so I can't test it.


using System;
using System.Windows.Forms;

public class MdiForm : Form
{
public MdiForm()
{
Text = "MdiExample";
IsMdiContainer = true;
Menu = new MainMenu();
MenuItem menuTest = new MenuItem();
Menu.MenuItems.Add(menuTest);
MenuItem menuItemNewMdiChild = new MenuItem();
menuTest.MenuItems.Add(menuItemNewMdiChild);
menuTest.Text = "Test";
menuItemNewMdiChild.Text = "New MDI Child";
menuItemNewMdiChild.Click +=new
EventHandler(menuItemNewMdiChild_Click);
}

private int formCount = 0;
private void menuItemNewMdiChild_Click(object sender, EventArgs e)
{
Form form = new Form();
form.Text = "Form " + (++formCount).ToString();
form.MdiParent = this;
form.WindowState = FormWindowState.Maximized;
form.Show();
}

[STAThread]
static void Main()
{
Application.Run(new MdiForm());
}
}

- Magnus
 
G

Guest

Thanks.

I think I'm using the lastest version of .Net. The
Framework is 1.1 with SP1 and the VS is 2003 (version
7.1.3088).

Thanks.
Nick
-----Original Message-----
It seems strange that I should need to set the MDI form's
Text property because it looks like it's automatically
handling this (just handling it incorrectly). Is this a
bug with the .Net Framework?

I agree that it's strange, and I distinctly remember having this problem
myself a while back.

However, it seems that I am unable to reproduce it now. The following
code is a short but complete example that works correctly for me when
compiled with VS.NET 2003 and VS 2005 beta1. What version are you
using? I wonder if it might be a bug that exists in .NET Framework 1.0
(VS.NET 2002) but has been fixed in the later versions. I don't have
access to 1.0 right now so I can't test it.


using System;
using System.Windows.Forms;

public class MdiForm : Form
{
public MdiForm()
{
Text = "MdiExample";
IsMdiContainer = true;
Menu = new MainMenu();
MenuItem menuTest = new MenuItem();
Menu.MenuItems.Add(menuTest);
MenuItem menuItemNewMdiChild = new MenuItem();
menuTest.MenuItems.Add(menuItemNewMdiChild);
menuTest.Text = "Test";
menuItemNewMdiChild.Text = "New MDI Child";
menuItemNewMdiChild.Click +=new
EventHandler(menuItemNewMdiChild_Click);
}

private int formCount = 0;
private void menuItemNewMdiChild_Click(object sender, EventArgs e)
{
Form form = new Form();
form.Text = "Form " + (++formCount).ToString();
form.MdiParent = this;
form.WindowState = FormWindowState.Maximized;
form.Show();
}

[STAThread]
static void Main()
{
Application.Run(new MdiForm());
}
}

- Magnus


.
 

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

Similar Threads

MDI Behaviour 2
MDI Child menu 1
MDI Problem 1
MDI window/parent form docking issue 1
MDI child for and it's menu 2
Closing form event 1
Stange problem with MDI parent - MDI child 1
MDI environment 1

Top