Click here to Skip to main content
15,903,724 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have a child which should be in the centre of parent page.

When I minimize the parent it should be in centre, same when I maximize parent form.

How?

I hope you reply to me.
Posted
Updated 25-Nov-10 22:19pm
v5
Comments
Arindam Tewary 26-Nov-10 3:43am    
Can you please make your question a bit clear. "I have a child which..."? what child ? Is that a child form that you are referring? Again you have written "in the centre of parent page". Is that form or page(web app/windows app). Totally confused.
Dalek Dave 26-Nov-10 4:19am    
Edited for Grammar.
narendra999 26-Nov-10 4:26am    
dave Sorry...it is a mdiform having a menu..in that i am having sub forms..when i click the menu in mdiform...its sub forms open..it should come at the centre of mdiform...when i minimise mdiform..those sub form also should be centre of that main form..windows application..c#...hope u got my point..thanks for ur reply..

If you are showing your child form as a Modal dialog (using ShowDialog) then you can set the StartPosition property to CenterParent and it will (initially) be correct.
If not, then you will have to do it manually:
Set the StartPosition to Manual
When you first show it, set it's Location relative to the current form
C#
frmChild f = new frmChild();
f.Top = ((Height - f.Height) / 2) + Top;
f.Left = ((Width - f.Width) / 2) + Left;
f.Show();
You will also have to handle the parent form Resize event and do the same there.

[edit]Why did I say "progress bar" instead of "child form"? Need coffee...[/edit]
 
Share this answer
 
v2
Comments
narendra999 26-Nov-10 4:07am    
thanks!What you told is working but when minimise of parent ...it doesnt...help if u have any idea...
Dalek Dave 26-Nov-10 4:19am    
Excellent answer.
If you're talking about a WinForm application I'd suggest you use a
TableLayoutpanel that is anchored to the Top, Left, Bottom, Right of its parent control.

Cheers

Manfred
 
Share this answer
 
Comments
Dalek Dave 26-Nov-10 4:19am    
Good call.
Hi narendra999

Ther is a property of the form to display position of the
On the menu click write this code

MIDL
Form form1=new Form();
form1.Show();
form1.MdiParent=this;
form1.StartPosition = FormStartPosition.CenterScreen;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900