Main window location

  • Thread starter Thread starter Ole Engvoll
  • Start date Start date
O

Ole Engvoll

Hi! After searching for one hour, I try you guys! In a MDI-based
winform, how can I get loaction for the main window regardless if I
click on a button in the main form or in a MDI-child? I only get the
MDI-child locations :-(. Thanx. Ole
 
Ole said:
Hi! After searching for one hour, I try you guys! In a MDI-based
winform, how can I get loaction for the main window regardless if I
click on a button in the main form or in a MDI-child? I only get the
MDI-child locations :-(. Thanx. Ole

I'd have to agree with Peter, your question is unclear. I thought you
were trying to find your program's path. If so, I'd try one of the
following:

System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)

Environment.CurrentDirectory

AppDomain.CurrentDomain.SetupInformation.ApplicationBase()

System.Reflection.Assembly.GetExecutingAssembly.Location
 
Hi! After searching for one hour, I try you guys! In a MDI-based
winform, how can I get loaction for the main window regardless if I
click on a button in the main form or in a MDI-child? I only get the
MDI-child locations :-(. Thanx. Ole

Add a property to your MDI child forms that is of type Form (or of whatever
type you named your MDI parent). Then, when you open a child form, set that
property to the parent. Then every child form can reference that property
and get the parent form's information.
 
All Control instances have a PointToClient() method and a
PointToScreen() method for converting between coordinate systems.  So if
you have a point in the coordinates for one control (e.g. an MDI child)
and you want that point in terms of the coordinate system for another
control (e.g. the MDI parent), all you have to do is first convert to
screen coordinates (i.e. use the first control's PointToScreen() method)
and then back to the client coordinate of the control you're interested
in (i.e. use the MDI parent's PointToClient() method).

If your question is not about converting points from one coordinate
system to another, then your question is unclear and you need to restate
it in a less ambiguous way.

Pete

Hi Pete!
My challenge is to get the coordinates from my application.exe so I
can position my dialog forms correctly (not only in the center). My
dialogs are running from child forms. I'll dig into the PointtoClient
and pointToScreen! Thanx! Ole
 
Add a property to your MDI child forms that is of type Form (or of whatever
type you named your MDI parent). Then, when you open a child form, set that
property to the parent. Then every child form can reference that property
and get the parent form's information.

Hi! Splended! Work perfectly! Thanx!
 
Back
Top