Solved

Need to place the location of a modal dialog

Posted on 2007-11-25
9
209 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
this.Location = new Point(this.Location.X + 50, this.Location.Y);

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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.

763 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

6 Experts available now in Live!

Get 1:1 Help Now