Solved

Need to place the location of a modal dialog

Posted on 2007-11-25
9
236 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
  • 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 use and create keystrokes in Netbeans IDE 8.0 for Windows.

829 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