CHAPTER 19 BUILDING A BETTER WINDOW WITH (Florida web design)
CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.WINDOWS.FORMS 619 Table 19-10. Select Events of the Form Type Events Meaning in Life Activated Occurs whenever the Form is activated, meaning the Form has been given the current focus on the desktop Closed, Closing Used to determine when the Form is about to close or has closed Deactivate Occurs whenever the Form is deactivated, meaning the Form has lost current focus on the desktop Load Occurs after the Form has been allocated into memory, but is not yet visible on the screen MDIChildActive Sent when a child window is activated The Life Cycle of a Form Type If you have programmed user interfaces using GUI toolkits such as Java Swing, Mac OS X Cocoa, or the raw Win32 API, you are aware that window types have a number of events that fire during their lifetime. The same holds true for Windows Forms. As you have seen, the life of a Form begins when the type constructor is called prior to being passed into the Application.Run() method. Once the object has been allocated on the managed heap, the framework fires the Load event. Within a Load event handler, you are free to configure the look and feel of the Form, prepare any contained child controls (such as ListBoxes, TreeViews, and whatnot), or simply allocate resources used during the Form s operation (database connections, proxies to remote objects, and whatnot). Once the Load event has fired, the next event to fire is Activated. This event fires when the Form receives focus as the active window on the desktop. The logical counterpart to the Activated event is (of course) Deactivate, which fires when the Form loses focus as the active window. As you can guess, the Activated and Deactivate events can fire numerous times over the life of a given Form type as the user navigates between active applications. When the user has chosen to close the Form in question, two close-centric events fire: Closing and Closed. The Closing event is fired first and is an ideal place to prompt the end user with the much hated (but useful) Are you sure you wish to close this application? message. This confirmational step is quite helpful to ensure the user has a chance to save any application-centric data before terminating the program. The Closing event works in conjunction with the CancelEventHandler delegate defined in the System.ComponentModel namespace. If you set the CancelEventArgs.Cancel property to true, you prevent the Form from being destroyed and instruct it to return to normal operation. If you set CancelEventArgs.Cancel to false, the Close event fires and the Windows Forms application terminates, which unloads the AppDomain and terminates the process. To solidify the sequence of events that take place during a Form s lifetime, assume you have a new MainWindow.cs file that handles the Load, Activated, Deactivate, Closing, and Close events within the class constructor (be sure to add a using directive for the System.ComponentModel namespace to obtain the definition of CancelEventArgs): public MainForm() { // Handle various lifetime events. Closing += new CancelEventHandler(MainForm_Closing); Load += new EventHandler(MainForm_Load); Closed += new EventHandler(MainForm_Closed); Activated += new EventHandler(MainForm_Activated); Deactivate += new EventHandler(MainForm_Deactivate); }
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.