Need to place the location of a modal dialog

I need to open a modal dialog and place it relative to the dialog which spawned it.

How do I do that?

thanks,
newbieweb
newbiewebSr. Software EngineerAsked:
Who is Participating?
 
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
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
 
Jaime OlivaresSoftware ArchitectCommented:
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
 
newbiewebSr. Software EngineerAuthor Commented:
Ok. Parent set to "this" I did.

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

How do I do that?


newbieweb
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
newbiewebSr. Software EngineerAuthor Commented:
And when I run this:

 makeOrderInCompleteDlg.Parent = this;

I get this exception:

[System.ArgumentException] = {"Top-level control cannot be added to a control."}
0
 
Jaime OlivaresSoftware ArchitectCommented:
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
 
Jaime OlivaresSoftware ArchitectCommented:
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
 
newbiewebSr. Software EngineerAuthor Commented:
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
 
newbiewebSr. Software EngineerAuthor Commented:
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
 
Jaime OlivaresSoftware ArchitectCommented:
this.Location = new Point(this.Location.X + 50, this.Location.Y);

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.