Quest: Setting Dlg Forms' OK & Cancel Buttons Correctly...

  • Thread starter Thread starter bj7lewis
  • Start date Start date
B

bj7lewis

I have two modal dlg forms that are invoked(seperately) by a main form but
the two modal dlg forms don't close when clicking the OK & Cancel buttons
setup as below...

Here the setup...

//In MainForm.cs...
//I Don't want the main form to close with enter and esc keys...
MainForm.AcceptButton = None; //Not in code...
MainForm.CancelButton = None; //Not in code...

//I use ExitApp button to exit app...
....
void ExitApp_Click(...)
{
Close();
}

//In My1stDlgForm.cs...
//I Do want the main form to close with enter and esc keys...
OKDlgButton.DialogResults = ....OK;
CancelDlgButton.DialogResults = ....Cancel;
....
My1stDlgForm.AcceptButton = OKDlgButton;
My1stDlgForm.CancelButton = CancelDlgButton;

//In My2ndDlgForm.cs...
//I Only want the form to close with enter keys...
OKDlgButton.DialogResults = ....OK;
....
My2ndDlgForm.AcceptButton = OKDlgButton;
My2ndDlgForm.CancelButton = ...None;

Note: End of codes above...

The program builds and runs but doesn't close. I have other C# programs that
the button worked and check the codes above with the old program an
everything matchs up...

Where else do I look to set this up...

Any help...
 
Did you set the DialogResult for the buttons properly ?
Yes, I used the form editor and just posted codes here to explain my
problem...
Sorry - OKDlgButton.DialogResult = ....OK;

Any more help...
 
How do you create&call the dialogs ?

bj7lewis said:
Yes, I used the form editor and just posted codes here to explain my
problem...

Sorry - OKDlgButton.DialogResult = ....OK;

Any more help...
 
How do you create&call the dialogs ?
I create the dialog same as MSDN and other how-to books show in the dialog
edtiorand call the dlgs as coded below...

In MainForm.cs in respect button handlers to show these dlg...
void ShowMy1stDlg_Click(...)
{
My1stDlgForm My1stDlgFormObj = new My1stDlgForm();
My1stDlgFormObj.ShowDialog();
}

//And

void ShowMy2ndDlg_Click(...)
{
My2ndDlgForm My2ndDlgFormObj = new My2ndDlgForm();
My2ndDlgFormObj.ShowDialog();
}

Just everything matchs in coding but I won't dlg close when clicking OK or
Cancel...

Any more help...
 
How do you create&call the dialogs ?
I create the dialog same as MSDN and other how-to books show in the dialog
edtiorand call the dlgs as coded below...

In MainForm.cs in respect button handlers to show these dlg...
void ShowMy1stDlg_Click(...)
{
My1stDlgForm My1stDlgFormObj = new My1stDlgForm();
My1stDlgFormObj.ShowDialog();
}
Oops, been a few since I look at my code(it not on this computer)...

I start this project a I have stated but forgot I don't move the call to the
forms to Main() so only the testing form is shown...

Like...
.... Main()
{
//Mutal exclusive commenting next three lines...
Application.Run(new MainForm);
Application.Run(new My1stDlgForm);
Application.Run(new My2ndDlgForm);
}

Doing a test again of...
void ShowMy1stDlg_Click(...)
{
My1stDlgForm My1stDlgFormObj = new My1stDlgForm();
My1stDlgFormObj.ShowDialog();
}

....works fine and the dialog closes back to MainForm focus...

So now what the difference(.Net interal) in how calling...
Application.Run(new My1stDlgForm);
....and...
My1stDlgForm My1stDlgFormObj = new My1stDlgForm();
My1stDlgFormObj.ShowDialog();
....cause how-to docs use Application.Run(new My1stDlgForm); more...

Any more help...
 
Application.Run (...) starts a message loop on the current thread and
displays the form; you should use application.run on your main form; and from
the main form display the dialogs:

MyDialog dlg = new MyDialog ();
if (dlg.ShowDialog () == DialogResult.OK)
{
// do something
}
 
Application.Run (...) starts a message loop on the current thread and
displays the form; you should use application.run on your main form; and from
the main form display the dialogs:

MyDialog dlg = new MyDialog ();
if (dlg.ShowDialog () == DialogResult.OK)
{
// do something
}
Yes, I do this normally but...
Application.Run(new My1stDlgForm);
....in Main() was only a test - if My1stDlgForm closes it works if it doesn't
work something wrong. Why do I need call Run() with the MainForm and then
ShowDialog() on My1stDlgForm?

That was theroy I 1st had but now I see the there is a difference in....

.... Main()
{
Application.Run(new My1stDlgForm);
}

....and...

void ShowMy1stDlg_Click(...)
{
My1stDlgForm My1stDlgFormObj = new My1stDlgForm();
My1stDlgFormObj.ShowDialog();
}

....that affect the excution of closing the form when calling Run() with the
My1stDlgForm...

I am just trying to dig deeper in into the differance cause later I could
have a true dlg app(in C#) like I done before in VS 6.0(MFC dlg app) that
have OK and Cancel button instead of a custom button handler close the
dialog...

Any more help...
 
Back
Top