473,669 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ShowDi alog();
frmAbout.Left = this.Left;
frmAbout.Top = this.Top;
....

thanks, Govert
Oct 2 '06 #1
2 4492
"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.ShowDi alog();
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 InitializeCompo nent())
_ptPosition = ptPosition;
}

* Use the position in the Load event handler:
private void About_Load(obje ct 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
12244
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: 300px; dialogLeft: 150px; edge: Sunken; center: Yes; help: No; resizable: No; status: No;');"> and the page loads in the modal dialog no problem.
2
3869
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 window. But I want modal dialog window, any ideas?? <form action="page2.asp" method="post" target="_blank"> <input type="text" name="username"> <input type="submit" name="submit"> </form>
3
6631
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 to its initial position when the user posts back (by clicking a button, etc.) I have all of the fundamentals for asp.net modal dialogs in place, such as using <base target="_self"> in the header... To reiterate the problem for the sake of...
2
8511
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 image to the end (i.e. bottom-right edge). After this, I open other form as modal dialog and after closing this modal form control with image scrolled to
4
10003
by: Paul Aspinall | last post by:
Can anyone advise how to display a form on top, and modal, without using ShowDialog?? Thanks
2
2641
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 form.setModal(1) before calling form.show(). All works as expected on Linux. The form is modal, not allowing the main window to received the focus. If I call the form from within itself, the topmost form is modal, and not of the previous forms will...
2
11681
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 to a control (containing a textbox and a button) on a windows form? I.e. I want the modal dialog to open just beneath the control that opened the dialog. -- Regards
4
4548
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 an option. I also need to check the values in a spread control on the forms before I close/dispose them. I'm using VB 2005. Is there some way for me to do this?
1
3562
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 as modal while others are opened up as modeless on this main form. Whenever some error occurs in client server communication we show it in modal message box. Now I ran into a case: a modal form is opened up on the main form. And some error...
0
8465
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8894
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8803
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8587
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6210
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2029
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.