Click here to Skip to main content
16,017,037 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi,

I'm using VB 2005.

I want processing in the parent form to halt after a show form is executed. When the child form is closed then control returns back to the parent form and processing continues.

How can this be done?

Thanks
Posted

Something else noone mentioned is if you show a Form with ShowDialog, you MUST also call Dispose on that form instance when you're done with it.
 
Share this answer
 
Comments
Dalek Dave 18-May-11 16:02pm    
Sage advice
First, there are not parent and child forms; there are owned and owner's form. If you don't know that it means you don't use this relationship, but you should. Make all non-modal non-main form owned by the main one; it is important for application activation integrity (try it with activation and you will see the great difference). Use System.Windows.Forms.Form.Owner for all non-main forms; also use Form.ShowInTaskbar = false for all owned forms — very useful.

Now, what is processing you want to halt? What is "form is executed"? There is no such notion. Shown? Modal or not? As to "control" returns back to the parent [owner — SA] form" — it happens by itself, but you should use ownership relationship, see the previous paragraphs. Final question is: do you want to show the owned form after closing ever again? Is so, you need to hide it instead of closing and show again when you need it. Another option is using it in a modal way, via Form.ShowDialog.

Hiding technique looks like this:
C#
using System.Windows.Forms;

//...

protected override void OnClosing(FormClosingEventArgs e) {
   if (e.CloseReason == CloseReason.UserClosing) {
      this.Hide();
      e.Cancel = true;
   }
}


—SA
 
Share this answer
 
Comments
Dalek Dave 18-May-11 16:02pm    
Good Answer
Sergey Alexandrovich Kryukov 18-May-11 16:07pm    
Thank you, Dalek.
--SA
When you open a new form, use ShowDialog() instead of Show() and you will get your wish.
 
Share this answer
 
Comments
Dalek Dave 18-May-11 16:02pm    
Simples!
Sergey Alexandrovich Kryukov 18-May-11 16:08pm    
Simple and acceptable, my 5. I mentioned it in my answer as well, along with other options.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900