Solved

Need to place the location of a modal dialog

Posted on 2007-11-25
9
224 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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WPF - Tooltips for ComboBox items 5 40
Needing an event fired when a row is added on a datagridview 4 37
Syntax error 9 45
Finally almost got it 5 25
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now