By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,952 Members | 1,073 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,952 IT Pros & Developers. It's quick & easy.

Problem displaying modal dialog boxes

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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 Im 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. Therere two forms C
Form1 and Form2. Form1 is the Main Form. Theres 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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.