473,380 Members | 1,243 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

MDI Child Window Problem

Hi,

I have an MDI application which has aboout 10 child windows. The way
the app needs to work is that only one window should be visible at a
time and it should be maximized within the parent window. I have set
all my child windows to be WindowState.Maximized but after showing 2
or 3 windows, the windows all drop back to Normal state.

I have tried various things to overcome this inclusing overriding
OnResize etc but none seem to give me the desired effect.

Can anyone suggest how I might achieve this?

Cheers

James
Nov 16 '05 #1
3 5590
Hi James,

Could you show us some sample code? I believe something in your code may trigger a WindowState reset or a Cascade.

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
James,

I would not recommend an MDI window for this. Rather, I would have a
tabbed dialog, or something of that nature, where the window changes with
each step. You are trying to make the MDI application do something that it
inherently should not.

In your situation, take the logic and the controls on the child forms
and place them in individual controls, and then show and hide the controls
in one window as needed.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"James Spibey" <ja**********@gmail.com> wrote in message
news:c2**************************@posting.google.c om...
Hi,

I have an MDI application which has aboout 10 child windows. The way
the app needs to work is that only one window should be visible at a
time and it should be maximized within the parent window. I have set
all my child windows to be WindowState.Maximized but after showing 2
or 3 windows, the windows all drop back to Normal state.

I have tried various things to overcome this inclusing overriding
OnResize etc but none seem to give me the desired effect.

Can anyone suggest how I might achieve this?

Cheers

James

Nov 16 '05 #3
Personally from what you say I would hide all forms until they are
selected -then it doesnt really matter about state, although you can reset
each child forms windowstate when it is reselected from the menu.

I am presuming you are selecting the childforms through a menu using a
MdiList. If this is so then the following wont work because the hidden forms
will not be displayed in the list so you would need to use another mechanism
to select the forms (eg. manually add them and remove them to menu).
--
Another way to "enforce the state" is to use the resize event of the mdi
child form, but the biggest problem with doing this is that I believe
Winforms needs to be able to change the state of the current form in order
to select and display another one.

I agree with Nicholas that maybe what you are doing is not ideally suited to
Mdi forms (especially since I've spent a while playing with your problem
without being entirely satisfied.
I believe the answer to this problem (if you insist on Mdi forms) is to use
a combination of the 2 above methods....
1. implement your own dynamic mechanism to select the forms, and for each
form selection implement an event handler that removes the lock on the
resizing of the form And then activates your selected form.
2. Whenever you add or select a form, change the WindowState to maximized
and add an event handler to lock the resizing of the form.

Please see following code which doesnt do this last bit but gives you a very
good idea about the first two methods. See my custom comments in the TODO
list to go to the pieces of code you will need to uncomment/ comment to try
both methods.

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

namespace WindowsApplication2
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItemAddchild;
private System.Windows.Forms.MenuItem menuItemShowall;
private System.Windows.Forms.MenuItem menuItemWindow;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

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

}

/// <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.menuItemAddchild = new System.Windows.Forms.MenuItem();
this.menuItemShowall = new System.Windows.Forms.MenuItem();
this.menuItemWindow = new System.Windows.Forms.MenuItem();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemAddchild,
this.menuItemShowall,
this.menuItemWindow});
//
// menuItemAddchild
//
this.menuItemAddchild.Index = 0;
this.menuItemAddchild.Text = "Add Child";
this.menuItemAddchild.Click += new
System.EventHandler(this.menuItemAddchild_Click);
//
// menuItemShowall
//
this.menuItemShowall.Index = 1;
this.menuItemShowall.Text = "Show All";
this.menuItemShowall.Click += new
System.EventHandler(this.menuItemShowall_Click);
//
// menuItemWindow
//
this.menuItemWindow.Index = 2;
this.menuItemWindow.MdiList = true;
this.menuItemWindow.Text = "&Window";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(728, 577);
this.IsMdiContainer = true;
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Mdi Demo";
this.Closing += new
System.ComponentModel.CancelEventHandler(this.Form 1_Closing);
this.MdiChildActivate += new
System.EventHandler(this.Form1_MdiChildActivate);

}
#endregion

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

private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
foreach (Forms.Form f in this.MdiChildren)
{
f.Dispose();
}
this.Dispose();
}

private void childForm_Resize(object sender, EventArgs e)
{
((Forms.Form) sender).WindowState = Forms.FormWindowState.Maximized;
}

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

}

private void menuItemAddchild_Click(object sender, System.EventArgs e)
{
//TODO: comment this to stop hiding mechanism -mechanism unfortunately
prevents the hidden forms appearing in the window list, therefore custom
list will need to be maintained
foreach (Forms.Form f in this.MdiChildren)
{
f.Hide();
}

int formnum = this.MdiChildren.Length; //create new title for form
Forms.Form childForm = new Form();
childForm.Text = formnum.ToString();
childForm.WindowState = Forms.FormWindowState.Maximized;
//TODO: comment this to stop anti-resizing mechanism -mechanism
unfortunately prevents selecting another form from window list because of
prevention of resized, therefore resize event handler will need to be
dynamically added and removed on selection of new form
//childForm.Resize += new EventHandler(childForm_Resize);
childForm.MdiParent = this;
childForm.Show();
}

private void menuItemShowall_Click(object sender, System.EventArgs e)
{
foreach (Forms.Form f in this.MdiChildren)
{
f.Show();
}
}
}
}


"James Spibey" <ja**********@gmail.com> wrote in message
news:c2**************************@posting.google.c om...
Hi,

I have an MDI application which has aboout 10 child windows. The way
the app needs to work is that only one window should be visible at a
time and it should be maximized within the parent window. I have set
all my child windows to be WindowState.Maximized but after showing 2
or 3 windows, the windows all drop back to Normal state.

I have tried various things to overcome this inclusing overriding
OnResize etc but none seem to give me the desired effect.

Can anyone suggest how I might achieve this?

Cheers

James

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: H2 | last post by:
Hi all, Any one know how to open a new windows in a child window using javascript? What I need to do is that, in my main page, there is a button, onclick, it opens one child windows. In the child...
4
by: Bonj | last post by:
Further to my last post, I have managed to get a child window to display. But its messages are routed to the same WNDPROC that the main window's messages are routed to - what is the way of...
2
by: Raj | last post by:
Hi All, I have a problem with trying to refresh the parent window from child window in order to update data in the parent window. The sequence of events are 1) I click a button in the parent...
1
by: Bill Borg | last post by:
Hello all, Simple chat app, where the site owner has a master window with all requests for chat, status of each room, etc., and child windows for each separate chat in which the owner is...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
4
by: Steve Barnett | last post by:
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...
4
by: Richard Lewis Haggard | last post by:
What is the mechanism by which a child window can notify its parent that it has been clicked on? -- Richard Lewis Haggard www.Haggard-And-Associates.com
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.