CIS162AD -- C Sharp (C#) -- Section 5832
Professor: Dave Hammer dwhammer@cox.net
http://members.cox.net/dwhammer/
Student: Patrick Moss patmoss@patmoss.com
http://www.patmoss.com/cis162ad/
Worksheet #5
Due Thursday, March 30, 2006
I. Definitions

   1. GUI = graphical user interface (p. 799)
      Instead of presenting the user with a "black screen"
      that displays only text, we can present the user with
      a high-resolution graphic screen display, including
      interactive mouse and keyboard for input. A GUI
      includes menus, buttons, pictures, and text that
      enable users to interact with applications during
      program execution.

   2. event (p. 798)
      An event is a notification from the operating system
      that an action, such as the user clicking the mouse
      or pressing a key, has occurred.
      
   3. event handler (p. 798)
      Event handlers are methods that define what should
      happen when an event such as a mouse click on a
      button or a click on the keyboard occurs.

   4. Form (p. 386+)
      Form is a predefined .NET class that includes a number
      of methods and properties used to create a basic
      Windows screen. A form inherits characteristics of
      the System.Windows.Forms.Form class.

      A Form is a rectangular GUI display that can contain
      various graphical elements, such as buttons, text boxes,
      labels, pictures, etc.

      Some of these elements can function as controls to
      allow the user to interact with the running program.

   5. Controls (p. 797)
      Controls are objects that can display and respond to
      user interactions, such as button clicks.

   6. derived class (p. 798, 386, 46, 29)
      One class can be derived from another ("base") class.
      The new class inherits all of the functionality of the
      base class. All classes are ultimately derived from
      the top-level class System.Object.

      C# utilizes the .NET Framework, which has a class 
      library that provides a very large collection of over
      2,500 resuable types (classes) available to any .NET
      language: C#, VB, J# and C++.

   7. Name property (p. 407)
      Each GUI element that can be "drawn" on a Windows Form
      has a Name property. When creating a control from the
      System.Windows.Form.Control namespace, the Name property
      gets or sets the name of the control.

   8. BackColor property (p. 407)
      A GUI element can have a foreground color and also a
      background color. When creating a control from the
      System.Windows.Form.Control namespace, the BackColor
      property gets or sets the background color of the
      control.

II. Questions or short essay

   1. What are important design considerations as you create
      the Graphic User Interface for your program? (p. 388+)
      a. Consistency
         Control interaction should be consistent. Colors and
         text should be consistent. 
      b. Alignment
         Use alignment for grouping items. Place similar items
         together. Use blank space to aid in grouping.
      c. Avoid clutter
         Do not crowd a form with too many controls. Buttons
         to be clicked should be large enough for ease of use.
         Text should be large enough to be clearly legible.
      d. Color 
         Choose color combinations that are clearly legible
         and also that are pleasing to the eye.
      e. Target Audience
         Consider the needs of the target audience, including
         their hardware display capabilities. For example, if
         they are viewing a GUI on a small PDA, then display
         few and smaller controls and minimal graphics.

   2. Describe five properties of the Form class. (p. 393+)
      a. BackColor: The form background color.
      b. Font: The form font.
      c. ForeColor: The form foreground color.
      d. Location: The x,y coordinates of the form.
      e. Size: The x and y dimensions of the form.
      f. StartPosition: WindowsDefault or CenterScreen.
      g. Text: The form title.

   3. What is the purpose of the Text property for a control?
      (p. 407)
      The Text property gets or sets the text associated with
      the control. For example, if the control is a button,
      the Text property value is displayed within the body
      of the rectangular button.

   4. What do you use TextBox objects for? (p. 412-416)
      The TextBox control object can be used to enter data or
      to display text during runtime. For example, we can
      display an information message or an error message to
      the user. And we can prompt the user, requesting input
      data or control decisions during program execution.

   5. Describe the difference between how console applications
      and windows applications work.
      a. Console applications present the user with a "black
         screen". Screen display and user interaction is via
         text input/output.
      b. Windows applications are GUI based, and usually include
         controls that respond to mouse clicks and keyboard input
         for dynamic user interaction with the running program.

   6. How do you put code for a button click event into your
      program?
      a. Create the button on the form.
      b. Double-click on the button.
      c. The button click event code skeleton will be displayed
         on the screen for this button.
      d. Enter the program code within the enclosing brackets for
         this click event skeleton.

 III. Programming Exercise
      Create the following program:
      Create a higher/lower guessing game using a graphical
      user interface. Allow a user to keep guessing until he
      guesses the number. Choose two colors for your game:
      one should be used to indicate that the value the user
      guessed is higher than the target; the other is used to
      indicate that the value the user guessed is lower than
      the target. With each new guess, change the form color
      based on whether the guess is higher than the target or
      lower. Keep a count of the number of guesses. when the
      the user hits the target, display a MessageBox indicating
      the number of guesses it took. Several approaches can be
      used to seed the target: one is to generate a random
      number by constructing an object of the Random class.
      For example, the following stores a random whole number
      between 0 and 100 in target:
        Random r = new Random();
        int target = r.Next(0, 100);
      Turn in your source code for this program.
                                 Return to Top