Click here to Skip to main content
16,011,988 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have a mdi form within which i am opening the mdichild forms.How to find the exact location of a panel placed inside the mdichild when it is opening inside the mdiparent form?
Posted
Comments
Sergey Alexandrovich Kryukov 30-Jun-11 17:38pm    
Always tag it! WPF, Forms, what?!
--SA

The location of the panel relative to what? The Location property is going to be an offset from the upper left corner of the container that it's sitting in, usually the form that's hosting the contorl, your MdiChild form.

But, you can map that location to the location inside the MdiParent or even the screen, with a little math.

Back to the base question... References to all Mdi Child forms are kept in the MdiParent forms MdiChildren property, which returns an Array of Form objects. You just need the index of the form you're looking for.

Or, if it's a form that you really need to get at, like you're asking now, you can keep your own reference to the form in a variable so you have ready access to it.

Then, it's just a matter of looking in that forms Controls collection for the Panel you're looking for, then looking at it's Location property.
 
Share this answer
 
Comments
Kunal Singha Roy 30-Jun-11 1:57am    
I understood what you said.But my problem is that i am not being able to find the position of the mdichild form relative to the Mdiparent form.
Dave Kreskowiak 30-Jun-11 7:25am    
Every Control has Location, Top and Left properties, including Forms. (Form inherits from Control.)

If you've got a reference the MdiChild form you want, you've got access to those properties.
Kunal Singha Roy 30-Jun-11 7:27am    
But when ever i am using mdichildform's location property it is showing (0,0)
Dave Kreskowiak 30-Jun-11 7:49am    
Then you're doing something wrong in your code. Without seeing what you're using to get at the child form there's not much I can tell you.
Kunal Singha Roy 30-Jun-11 7:56am    
When i used point to screen property it is giving proper result.What is the difference between point to screen and point to client property.
First of all, if you're creating tabbed interface, you should never use MDIChildForm, MDIParent and other MDI stuff. What you call "Tabbed MDI" is not MDI at all.

And this is good. I would advise: never use MDI! But Tabbed UI is quite good.
See:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^].

You never need to know exact location of this panel. The question is: location relative to what? You can translate all coordinates to scree coordinates. How to do it depends on what UI library you use: WPF, Forms or something else. You will easily find this conversion; for example, see System.Windows.Forms.Control.PointToScreen.

Always tag UI library when you ask a UI-related question!

You should always avoid using explicit coordinate of control. Instead, try to use Dock (or DockingPanel) with Padding and/or Margin.

Please see my direction for UI desing:
GUI Apperance - C#.Net[^],
Zom Out malfunctions when Screen resolution changes[^],
how to dock button so that it can adjust with the form[^] (code sample here).

—SA
 
Share this answer
 

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