Link to home
Start Free TrialLog in
Avatar of Miles Thornton
Miles ThorntonFlag for United States of America

asked on

Dialog Form Behavior question

I have a winforms app (VS2010, .Net 4, on Windows 7 64-bit - if that matters) in which I have a main form (frmMain) that calls a FixedDialog form (frmData) to gather information. frmData has to call another FixedDialog form (frmContact) for additional data. I need to use frmData.ShowDialog() to have a result to use to control the forms refresh behavior:
            frmContact contact = new frmContact(true);
            DialogResult dr = contact.ShowDialog();
            if (dr != System.Windows.Forms.DialogResult.Cancel) {...}
 
My problem is that when I close frmContact, frmData (the caller) also closes - I don't want frmData to close - the user very likely isn't done with the data entry.

How do I manage to get frmData to NOT close when frmContactData closes?

Avatar of Gautham Janardhan
Gautham Janardhan

ideally it should not close..can you post your code please.
ASKER CERTIFIED SOLUTION
Avatar of shadow77
shadow77

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Probably you are closing frmData (the  caller) & frmContact instances together.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Main Form Designer.cs file
Form1.Designer.cs
DialogBox1.cs
DialogBox1.cs
zip the whole solution and upload. That will be easier rather giving only files.
DialogBox1 Designer.cs
DialogBox1.Designer.cs
DialogBox2.cs
DialogBox2.cs
DialogBox2 Designer.cs
DialogBox2.Designer.cs
Complete Project Zip File..
DialogsDemo.zip
Create an Windows Forms project in Visual Studio then in solution explorer right click on solution and click on Add Existing Files then Add all the files in the zip file to it.. build the solution and run it..
It's not closing. It's all working well with your code
Avatar of Miles Thornton

ASKER

Thank you so much for all the advice and the example! I am exploring Starlight551's project now. I am posting my project (zipped) for you to explore - Wow, what a pain! I have had to remove a lot of the files b/c their extensions are not allowed; I finally settled for just the forms and their .cs files...

Please be advised that I am using Nevron controls so if you don't have their library, most of the editing controls won't render and the solution won't compile as-is.

As near as I can tell The problem child is found at: NovaTech.Business.Admin.GUI.frmMain.tsbtnAddNewItemJobNumber_Click(object sender, EventArgs e) {}  I also started considering with using frmJob.Show() with a file-system flag file to trigger a refresh... A sub-optimal solution at best.
justTheForms.zip
@Shadow77: You asked: "Is the AcceptButton property for your form set to the button that the user clicks to activate the contact form?" - No, the AcceptButton property of each form is set to that form's OK button, and the sub-form activation is a different button. So... Thanks, but that's not it at all.
I downloaded individual files, Create new empty solution, added project and files

I don't see any issue with your code. Verify once again or follow the above suite.
@Mathiyazhagan: I checked into what you said and even configured that way; both forms close.

It's odd; if I use .Show() in the main form and .ShowDialog() in the second form, then the behavior of the forms is what I want; I just don't get why .ShowDialog() doesn't work.

I am out of time; I'm going to have to find an alternative way to determine the result of the second form's closing at runtime.

Thank you everyone for your time and efforts! I really do appreciate it!
Out of time, gotta go with a workaround