473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

position of modal form

Here's my C# newbie question:

How do I set the position of a modal form?

This (correctly) positions top left of the form at the position of the
main form:
....
Form frmAbout = new About();
frmAbout.Show();
frmAbout.Left = this.Left;
frmAbout.Top = this.Top;
....

But this doesn't work
....
Form frmAbout = new About();
frmAbout.ShowDialog();
frmAbout.Left = this.Left;
frmAbout.Top = this.Top;
....

thanks, Govert
Oct 2 '06 #1
2 4477
"Govert J. Knopper" <gk*@nodots.d.e.r.e.u.m.a.u.x.comwrote in message
news:45**********************@news.kpnplanet.nl...
Here's my C# newbie question:

How do I set the position of a modal form?

This (correctly) positions top left of the form at the position of the
main form:
...
Form frmAbout = new About();
frmAbout.Show();
frmAbout.Left = this.Left;
frmAbout.Top = this.Top;
...

But this doesn't work
...
Form frmAbout = new About();
frmAbout.ShowDialog();
frmAbout.Left = this.Left;
frmAbout.Top = this.Top;
The latter fails to do what you want because the last two lines aren't
executed until you dismiss the modal form.

If you want to set the position of the modal form, you need to do it in code
that will execute while the form is being displayed. For example, in the
form's Load event handler. One solution might be as follows:

* In your modal form (dialog) class, add a private Point field:
private Point _ptPosition;

* Change the constructor to take a Point as a parameter and set the
private field:
public About(Point ptPosition)
{
// do other stuff (like InitializeComponent())
_ptPosition = ptPosition;
}

* Use the position in the Load event handler:
private void About_Load(object sender, EventArgs e)
{
Location = _ptPosition;
}

* And finally, in your caller take advantage of the changed constructor:
About frmAbout = new About(Location)

Pete
Oct 2 '06 #2
Thanks!

Govert
Oct 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: martin de vroom | last post by:
Hi, I have a web page that opens a modal dialog (client side) in the following manner onclick="window.showModalDialog('/dialog.asp',null,'dialogHeight: 200px; dialogWidth: 400px; dialogTop:...
2
by: Matt | last post by:
I want to know how to submit the form data to a modal dialog window? The following is page1.asp, and when the user clicks submit button, it will post the form data to page2.asp by opening a new...
3
by: Rod | last post by:
I have an asp.net application where some of the interaction with the user is through modal dialog windows. This works very well except for the annoying fact that the dialog window always returns...
2
by: Leonid Shirmanov | last post by:
Hi, I have a form with control placed on it. Control has the image painted on its graphics. Size of the contol is greater than size of the form and scroll bars appear in the form. I scroll the...
4
by: Paul Aspinall | last post by:
Can anyone advise how to display a form on top, and modal, without using ShowDialog?? Thanks
2
by: Mike | last post by:
Hi, I'm having a problem with modal forms on windows. I've written a very short test program, with a main window and a form called from the main window. The form is set to modal with...
2
by: Dave Anson | last post by:
I have created a custom datetimepicker (following on from a previous thread "DateTimePicker color"). How do I set the position of a Modal Dialog (a control containing a month calendar) relative...
4
by: =?Utf-8?B?Z2luYWNyZXNzZQ==?= | last post by:
I am trying to close/dispose multiple instances of a form but because they are modal and hidden, they do not show up in My.Application.OpenForms. They must be modal, so making them modeless is not...
1
by: Mohit | last post by:
Hi all, I am working on a windows based client server application with multiple forms. All forms are having custom title bars with no default bars. There is one main form. Some forms are opened up...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.