Thread: Lesson 9 Tryit
View Single Post
  #2 (permalink)  
Old July 14th, 2012, 01:57 PM
Rod Stephens's Avatar
Rod Stephens Rod Stephens is offline
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Hi cellison,

I think a later chapter deals with the problem of the main form trying to repost a form that has been destroyed.

For modal dialogs, by far the most common strategy is to make the button's Click event handler create a new form every time. That resets the form so you know it is in its starting state and more importantly keeps everything local so you don't have those class-level form instances floating around to confuse people.

If data needs to be saved and used to initialize the dialog before it is displayed, the main form stores it somewhere in variables.

People sometimes use another strategy for forms that are not modal dialogs. For example, suppose you have a bunch of secondary forms that the user may want to display often, possibly at the same time. In that case you can use the approach followed by Lesson 9.

To prevent the form from being destroyed, you can make the FormClosing event handler cancel the close and hide the form. Note that with this approach, you cannot easily "cancel" the form.

I'll post some examples in the next couple days on C# Helper.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)