I have set a form as a child of an MDI form which has its WindowState set to Maximized.
When I open that form from an MDI container, it doesn't open in Maximized state. Why is this happening and how can I make it open maximized?
This is how I am showing child form from mdi container.
private void ShowNewForm(object sender, EventArgs e)
{
FormChild childForm =开发者_如何转开发 new FormChild ();
childForm.MdiParent = this;
childForm.WindowState = FormWindowState.Maximized;
childForm.Text = "Window " + childFormNumber++;
childForm.Show();
}
Found the best possible method to solve this.. Just use two lines :
frm r = new frm();
r.MdiParent = this;
r.Show();
r.WindowState = FormWindowState.Minimized;
r.WindowState = FormWindowState.Maximized;
As it turns out, the desired result is obtained, if the form is first minimized, and then maximized!
There is genuinely a bug in the Framework. The Framework seems to get confused if you set the WindowState to Maximized from the GUI. You end up with a strange state somewhere between Maximized and the Default size.
With the WindowState set like this, attempts to correct it in code are ignored. The code below produced the image above.
private void ShowNewForm(object sender, EventArgs e)
{
Form1 childForm = new Form1();
childForm.MdiParent = this;
childForm.Text = "Window " + childFormNumber++;
childForm.Show();
childForm.WindowState = FormWindowState.Maximized;
}
Subsequent calls to ShowNewForm() will display properly, but the first child will always exhibit this behavior.
Simply return the WindowState to normal in the GUI, then use code to maximize the form as demonstrated in the above code.
My versions:
C# Express 10.0.40219.1 SP1
.NET 4.0.30319 SP1
I have found that if another visible form calls into a second MIDChild and sets the text then that MDIChild loses track of its WindowState.
Try commenting out
childForm.Text = "Window " + childFormNumber++;
and see if that fixes your problem. Looks like a framework bug to me.
The form must first be shown, then maximized!
private void ShowNewForm(object sender, EventArgs e)
{
FormChild childForm = new FormChild ();
childForm.MdiParent = this;
childForm.Text = "Window " + childFormNumber++;
childForm.Show();
childForm.WindowState = FormWindowState.Maximized;
}
Select Your Child form Press F4 and set WindowState to normal
if you want to maximize child you have to set form property to normal
and write code like:
FormChild childForm = new FormChild ();
childForm.MdiParent = this;
childForm.Show();
childForm.WindowState = FormWindowState.Maximized;
You can try the following:
form1 obj = new form1 ();
obj.MdiParent = MDIGracular.ActiveForm;
obj.StartPosition = FormStartPosition.CenterParent;
obj.WindowState = FormWindowState.Minimized;
obj.Dock = DockStyle.Fill;
obj.Show();
obj.WindowState = FormWindowState.Maximized;
I finally found the solution and it's working for me correctly. This is the problem with Framework when we are dealing with MDI Form and we can't solve this only by changing the WindowState Property to maximized. We need to write below code:
Code: Form1 form= new Form1 form.Dock= DockStyle.Fill;
This Dock property will maximized the child forms under MDIForm and make sure all child forms WindowState property should be Normal.
I found another solution. First, add the System.Windows.Forms.Panel element to the form. Set property
this.root.Dock = System.Windows.Forms.DockStyle.Fill;
Then, all other controls are positioned inside the Panel. In this case, FormWindowState.Maximized can be set anywhere and works reasonably.
FormChild childForm = new FormChild ();
childForm.MdiParent = this;
childForm.Text = "Window " + childFormNumber++;
childForm.Show();
childform.BringToFront();
childForm.WindowState = FormWindowState.Maximized;
hope it will help
It's simple.
In child form load event write code:
this.WindowState = FormWindowState.Maximized;
Ignore set the WindowState on design mode (Properties-->WindowsState-->Maximized)
Then after show form:
childForm.WindowState=FormWindowState.Maximized;
My versions:
- Visual Studio 2010
- .NET 3.5
I had the same Problem and all I found couldn't help it. I have a parent (main) window and several child windows. When an child window is closed, it is instead hidden and activated when opened again.
Whatever I tried, when a hidden child window is activated again, it is in a semi-maximized state, when no other child window is open. If an once hidden and avtivated window is set to state normal, its bar is displayed behind the parent window.
Now I found out, that this only happens, when the child window is hidden in maximized state. So I set the WindowState to Normal in the FormClosing Event before the window is hidden and all is working as expected.
In your childForm
properties, set the Windows State
property to Normal
. Then, in the childForm
Load
method add the following line:
this.WindowState = FormWindowState.Maximized;
I think I know now, why you have to set
childForm.WindowState=FormWindowState.Maximized;
after
childForm.Show();
When you set a form to maximized, it uses all of the space it gets, so a normal form is maximized to the whole screen, a MDI child form is maximized to the specified space inside the MDI parent form. But this usable space is set with the "show" command. So if you set the windowstate of a child form to maximized before the "show" command, it simply doesn't know how big it can get and therefore is displayed in the size of windowstate "normal", but otherwise it is a maximized form.
The only way to get a MDI child form to always open maximized correctly without too much flickering is to set it to another windowstate before the "show" command and maximize it after it is shown.
精彩评论