Solved

Need to place the location of a modal dialog

Posted on 2007-11-25
9
246 Views
Last Modified: 2013-12-16
I need to open a modal dialog and place it relative to the dialog which spawned it.

How do I do that?

thanks,
newbieweb
0
Comment
Question by:newbieweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20346343
before calling the dialog from a primary dialog, set its Parent property to primary dialogs's 'this' reference.
So in the Load event of secondary dialog, use this Parent property to obtain the coordinates of it and change secondary's Location property.
0
 

Author Comment

by:newbieweb
ID: 20346385
Ok. Parent set to "this" I did.

When I try and set Location, it's read only.

How do I do that?


newbieweb
0
 

Author Comment

by:newbieweb
ID: 20346398
And when I run this:

 makeOrderInCompleteDlg.Parent = this;

I get this exception:

[System.ArgumentException] = {"Top-level control cannot be added to a control."}
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20346410
change the location from the secondary's Load event. Something like:

void yourSecondForm_Load(......)
{
        // other tasks
        this.Location = new Point(Parent.Location.X + Parent.Size.Width+1, Parent.Location.Y + Parent.Size.Height+1);
}
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20346421
That's because dialog is set as top-level. This will work in most situations:
From the caller:
makeOrderInCompleteDlg.Tag = this;

And then:
void yourSecondForm_Load(......)
{
        // other tasks
        Form parent = (Form)this.Tag;
        this.Location = new Point(parent.Location.X + parent.Size.Width+1, parent.Location.Y + parent.Size.Height+1);
}


0
 

Author Comment

by:newbieweb
ID: 20346761
I se the parent before calling Show.  Is this what you meant?

                   MakeOrderInComplete makeOrderInCompleteDlg = new MakeOrderInComplete(handles, orderNum);
                    makeOrderInCompleteDlg.Parent = this;
                    makeOrderInCompleteDlg.Show();


newbieweb
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 20346884
yes, but as you are using an overloaded constructor, will be more elegant to do this:

 MakeOrderInComplete makeOrderInCompleteDlg = new MakeOrderInComplete(this, handles, orderNum);
 makeOrderInCompleteDlg.Show();

in the dialog's constructor, save the parent reference as a class member, and wait until the Load event to try to move your window as suggested.
0
 

Author Comment

by:newbieweb
ID: 20346916
Yes, that looks much nicer.

I have all that working, and can set the location to be the same as the parent.

this.Location = parent.Location;

But need to find the type so I can create a new one, then assign it to

this.Location

I can not do this:

this.Location.X += 50;

How would I do that?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20347074
this.Location = new Point(this.Location.X + 50, this.Location.Y);

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question