ShowDialog() Method

hay all ....
I have a form and when I display that form on the screen I useShowDialog() method
now.. when I display a Message usingMessageBox.Show() method and once I click on the ok btn for that message
the parent form gose to hide ...
what i have do to prevent that
thank you
[960 byte] By [holy_spirit] at [2008-1-9]
# 1

I tried what you given here.but the form is not hiding.it works properly.may be you can explain how ur code works.

Vidhura at 2007-10-3 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
Code Snippet

private void btnOk_Click(object sender, EventArgs e)
{
CheckingFieldsResult result = this.CheckFields();
this.DoEdit(result);
}

private void DoEdit(CheckingFieldsResult result)
{
switch (result)
{
case CheckingFieldsResult.DurationError:
MessageBox.Show("Possible Errors:\r\n\t1:Duration less than (current position- trimIn+ 5)\r\n\t2:Duration more than TotalFrames\r\n\t3:Duration = trimIn", "ICTechPlayer", MessageBoxButtons.OK, MessageBoxIcon.Information);
break;

case CheckingFieldsResult.TrimInError:
MessageBox.Show("TrimIn must be more than zero, and less than (trimOut- duration- 5", "ICTechPlayer", MessageBoxButtons.OK, MessageBoxIcon.Information);
break;


and once I press Ok btn the form gose to hide !!!!

is that clear ?

holy_spirit at 2007-10-3 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3

Are you sure the form hides? I think the form would actually close.

ShowDialog is waiting for a button press of some kind, I don't know hte exact details but basically the MessageBox is sending the button click through the forms and propagating. The behaviour then closes your modal dialog as well.

Zamial at 2007-10-3 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 4
Nice explanation... (closing form) I think that what happend
so how can we prevent that ?
holy_spirit at 2007-10-3 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 5

In the past I have either not used ShowDialog(); or do not use a MessageBox.

Either implement a status bar perhaps or a label to show your message. If the MessageBox result is required whereby you have a yes or no question perhaps, instead you can use a checkbox on the form.

The problem is very annoying though Smile

The final third and great option I can offer is instead of using the MessageBox you can create your own message box form and show it.

Zamial at 2007-10-3 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 6
Is there any Method that can prevent a form from being close for a condition?
Cuz I dont wanna use any on of your options
holy_spirit at 2007-10-3 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 7

To prevent a form from closing use the following event handler for FormClosing event:

Code Snippet

private void YourForm_FormClosing(object sender, FormClosingEventArgs e)

{

e.Cancel = true;

}

that will prevent the form from closing. You better sue a conditional statement as if you leave it like this it will never close.

Fábio at 2007-10-3 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 8
That exactly what I searching for
Thank you
holy_spirit at 2007-10-3 > top of Msdn Tech,Windows Forms,Windows Forms General...