473,402 Members | 2,061 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,402 software developers and data experts.

Problem displaying modal dialog boxes

I'm following the example from the MSDN library on how to create modal dialog
boxes in C#, but something isn't working properly. If I create a modal
dialog box and show it using ShowDialog(), the main form behind the dialog
box is still enabled and can operate normally. If I use MessageBox.Show() to
show a message box, the main form is disabled until the dialog box
terminates. How can I make a custom dialog box do this?
Apr 14 '06 #1
4 9475
Hi,
Thank you for posting. From your post, my understanding on this issue is:
You can not make a Windows form show in modal mode. If I¡¯m off base,
please feel free to let me know.
If you want to show a Windows form in modal mode, you should use
ShowDialog method to show it. There is an example. There¡¯re two forms ¨C
Form1 and Form2. Form1 is the Main Form. There¡¯s a button on Form1. You
can open Form2 if you click the button. To show Form2 in modal mode, the
code in Form1 should be:
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.ShowDialog(this);
}
The ShowDialog method has an optional argument, owner, that can be used to
specify a parent-child relationship for a form. Parent-child relationship
means that if the parent form is minimized, the child form will be
minimized too.
Please let me know if you have any other concerns, or need anything else.

Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==

Apr 14 '06 #2
Hi, Linda. Thanks for your response. The code you provided is exactly what
I saw in the MSDN Library documentation. I tried that, and it does work as a
modal dialog box - i.e. the code immediately after ShowDialog() doesn't
execute until you close the dialog box. However, the main form is still
running, and you can click on buttons, press keys, etc., behind the dialog
box. When calling MessageBox.Show() to use the built-in message box instead
of a custom form, however, the main form becomes disabled until the message
box is closed. How can you make a modal dialog box have the same effect? I
don't want the user to be able to do things on the main form until the dialog
box is closed.

Mike

"Linda Liu [MSFT]" wrote:
Hi,
Thank you for posting. From your post, my understanding on this issue is:
You can not make a Windows form show in modal mode. If I¡¯m off base,
please feel free to let me know.
If you want to show a Windows form in modal mode, you should use
ShowDialog method to show it. There is an example. There¡¯re two forms ¨C
Form1 and Form2. Form1 is the Main Form. There¡¯s a button on Form1. You
can open Form2 if you click the button. To show Form2 in modal mode, the
code in Form1 should be:
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.ShowDialog(this);
}
The ShowDialog method has an optional argument, owner, that can be used to
specify a parent-child relationship for a form. Parent-child relationship
means that if the parent form is minimized, the child form will be
minimized too.
Please let me know if you have any other concerns, or need anything else.

Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==

Apr 14 '06 #3
On Fri, 14 Apr 2006 09:46:02 -0700, mpreston
<mp******@newsgroups.nospam> wrote in
<78**********************************@microsoft.co m>:
Hi, Linda. Thanks for your response. The code you provided is exactly what
I saw in the MSDN Library documentation. I tried that,
Did you supply the reference to the parent window as the argument to
ShowDialog()?
and it does work as a modal dialog box - i.e. the code immediately
after ShowDialog() doesn't execute until you close the dialog box.
However, the main form is still running, and you can click on
buttons, press keys, etc., behind the dialog box.


I created a quick test program. Here's the relevant code from
Form1.cs:

private void button1_Click(object sender, System.EventArgs e)
{
Form2 frm = new Form2();
frm.ShowDialog(this);
}

Form2 was displayed and Form1 was disabled. I could not bring it to
the foreground, give it the focus or click on any of its child
controls.

What version of .NET are you using? I'm using 1.1.
--
Charles Calvert | Software Design/Development
Celtic Wolf, Inc. | Project Management
http://www.celticwolf.com/ | Technical Writing
(703) 580-0210 | Research
Apr 16 '06 #4
Hi Mike,

Thank you for your reply.

I have created a test project with the code in my previous message, and it
works well. I think the problem may be related to the actual code in your
project. If your project is not complex, you can send it to me to have a
look. If the project is too large to send by email, you may create a simple
winform project and copy your related code into it, so that the new project
also can reproduce the problem and send the new project to me please. To
get my actual email, Please remove the ¡°online¡± from my display email.

Thanks.

Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==

Apr 17 '06 #5

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

Similar topics

1
by: Laxmikant Rashinkar | last post by:
Hello, from inside a button handler, I am launching a dialog box that contains lables and text boxes. The dialog box is launched using dlg.Show(). In this situation the contents of the text...
3
by: Andrew Baker | last post by:
OK this has me perplexed, puzzled and bamboozled! I have a remoting service which I displayed a message box in. I then wondered what would happen if a client made a call to the service while the...
2
by: Brian Henry | last post by:
If i have a window showing like this <script>window.showModalDialog('../weblinks/default.aspx','','unadorned:yes' );</script> how can i get it to return a value to its calling page? I want to...
2
by: barney | last post by:
Hi Folks, One of the users running our web application is reporting that in modal dialog boxes, they can only see half the content. It seems that even though I have explicitly set font sizes...
2
by: des | last post by:
Hi, I would like to create a modal dlalog page for displaying some error message. I just want to know, is there anyway to pop out the modal dialog page in the vb.net code? Because each time i...
0
by: adam | last post by:
I'm writing an Intranet application that uses Modal Dialog boxes and have embedded a page within an iframe on another page that is opened modally, so that the postbacks work as normal. When...
0
by: dattaforit | last post by:
Hello Friends, I am using VC++ 2005. I have an application for C#. In this application i want to display a modal dialog box or a modal form in a thread. I have on thread running and in that...
2
by: one.1more | last post by:
I want to make a text game using javascript dialog boxes. i learned about confirm boxes but its not helpful(http:// www.javascriptmall.com/learn/lesson6.htm) 1. for ex, in the confirm boxes,...
10
by: brendanmcdonagh | last post by:
Hi all, I'm just getting to grips with java and have set my self a challenge to consolidate my learnings so far as well as implement new learnings. I want to enter a load of possible things to...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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
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.