Web site design - CHAPTER 19 BUILDING A BETTER WINDOW WITH
CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.620 STEM.WINDOWS.FORMS Figure 19-5. The life and times of a Form-derived type In the Load, Closed, Activated, and Deactivate event handlers, you are going to update the value of a new Form-level System.String member variable (named lifeTimeInfo) with a simple message that displays the name of the event that has just been intercepted. As well, notice that within the Closed event handler, you will display the value of this string within amessage box: private void MainForm_Load(object sender, System.EventArgs e) { lifeTimeInfo += “Load eventn”; } private void MainForm_Activated(object sender, System.EventArgs e) { lifeTimeInfo += “Activate eventn”; } private void MainForm_Deactivate(object sender, System.EventArgs e) { lifeTimeInfo += “Deactivate eventn”; } private void MainForm_Closed(object sender, System.EventArgs e) { lifeTimeInfo += “Closed eventn”; MessageBox.Show(lifeTimeInfo); } Within the Closing event handler, you will prompt the user to ensure she wishes to terminate the application using the incoming CancelEventArgs: private void MainForm_Closing(object sender, CancelEventArgs e) { DialogResult dr = MessageBox.Show(”Do you REALLY want to close this app?”, “Closing event!”, MessageBoxButtons.YesNo); if (dr == DialogResult.No) e.Cancel = true; else e.Cancel = false; } Notice that the MessageBox.Show() method returns a DialogResult type, which has been set to a value representing the button clicked by the end user (Yes or No). Now, compile your code at the command line: csc /target:winexe *.cs Now run your application and shift the Form into and out of focus a few times (to trigger the Activated and Deactivate events). Once you shut down the Form, you will see amessage box that looks something like Figure 19-5. Now, most of the really interesting aspects of the Form type have to do with its ability to create and host menu systems, toolbars, and status bars. While the code to do so is not complex, you will be happy to know that Visual Studio 2005 defines a number of graphical designers that take care of
We recommend high quality webhost to host and run your jsp application: christian web host services.