6.1. Our First Windows Forms Program

For our first Windows Forms program, we'll again greet the user, as we did in Chapter 1, except that this time we'll do it interactively through a graphical user interface (GUI). The initial window is pictured in Figure 6.1.

Figure 6.1. Initial Window


The window is represented as a Form class object. The title bar has been set to the string Hello, Windows Forms! As the user enters his or her name in the text box, we update the title bar to the text entered by the user. We do this through an event handler associated with the text box. The event is triggered whenever the content of the text box is altered. Within the form, we have placed the following controls.

  • A Label object with the associated text Please Enter Name.

  • A TextBox object to the right of the label, where the user enters her name.

  • Two Button objects—one labeled OK and the other labeled Quit.

When the user clicks OK, a dialog window pops up to formally greet him or her. This window displays not only the user's name, but the current date and time as well, as pictured in Figure 6.2.

Figure 6.2. Greeting Dialog


If the user clicks OK without having filled in the text box, a dialog window pops up requesting the user to fill in the text box (see Figure 6.3).

Figure 6.3. Bad Data Dialog


If the user presses Quit, a dialog box pops up asking the user to confirm (see Figure 6.4). Notice that the icon and the number of available buttons change for each dialog box. (We look at how to program events such as button clicks in Section 6.4.)

Figure 6.4. Are You Sure? Dialog


If the user presses OK, we pop up a final goodbye dialog box without an icon (see Figure 6.5.).

Figure 6.5. Ok, Bye Dialog


And that's our first Windows Forms application. In the next sections we'll look at how it's implemented—through control widget drag-and-drop GUI design for the look of the form and event callback programming for its behavior.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.78.102