Hi All,
I want to do two things.
1. I have a MDI and when a specific form load it should position in the middle of the MDI. For example login window should load in the middle of MDI.
2. I have a MDI and I can load some windows inside that. And I some of those windows load other windows too. I want to position them in the middle of window which is used to call them
Please post some sample code on how to do this.
Loading
Kirtan PatelPosted Sep 8, 2009, 8:53 AM
try below code now it will work
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.MdiParent= this;
f2.StartPosition = FormStartPosition.CenterScreen;
f2.Show();
}
Kirtan PatelPosted Sep 8, 2009, 9:25 AM
Make MDIFroms KeyPreview Property to True
then here Is Code For key press Event of MDI Form Now it will Open Form2 When i Press ' A' From keyboard ( Shift+A) key
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)(65))
{
Form2 f2 = new Form2();
f2.MdiParent = this;
f2.StartPosition = FormStartPosition.CenterScreen;
f2.Show();
}
}
garukaPosted Sep 8, 2009, 9:02 AM
Sweet. It's working. I think issue No1 is solved now.
But any idea about issue two? Do I have to handle this in from level instead of MDI level?
garukaPosted Sep 8, 2009, 8:35 AM
There is a problem in that approach which I already tried. The problem is related to part 1. My Login form loads when the MDI is loading. So when I add that code segment I get the error "Top-level control cannot be added to a control."
About the second part..the problem that child window is loaded from MDI window. the MDI should listern to key board and load the window in the middle of currently focused form inside MDI.
So I'm sorry I don't think that suggestion will work.
Kirtan PatelPosted Sep 8, 2009, 8:25 AM
here is solution for your Problem
you can Do it By Both Way By Code and Setting Property
Just Setting StartPositon Propety of Form to "CenterScreen" of Which you trying to show in MDI form
or By Coding You can do it Like below Code
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Parent = this;
f2.StartPosition = FormStartPosition.CenterScreen;
f2.Show();
}