CSCI 220 Programming With Visual Basic
Lecture 2- Forms and Controls

Objects 
  Characteristics
    Building blocks of Visual Basic
    Object types already created - we make new instances
    Object types 'borrowed' from Windows environment
    Individual entities that are somewhat self-contianed
    Can interact with other objects
    Some behavior of objects is 'built - in'
      (command buttons being pushed down)
  An object has:
    Properties
      the individual characteristics of the object
    Events
      Stimuli from the user, environment, or other objects 
      that the object can respond to
    Methods
      Specialized commands that the object can do

Selected controls:
  Form:
    Main Property:  Varies
    Main Event:  Load (activated whenever form shows up on screen)
    Main Uses:
      Serves as container for all other controls
      Background for program
      Load event used to contain code for early in the program run
  Picture box
    Main Property:  Picture
    Main Event: Click
    Main Uses:
      Display a graphic image on the screen
  Label
    Main Property:  Caption
    Main Event:Click
    Main Uses:
      Display text on screen
      Show text that user cannot directly change
      Often works like PRINT command in other languages
  Text Box
    Main Property:  Text
    Main Event:  Change
    Main Uses:  
      Display CHANGEABLE text on screen
      Allow user to directly input text on screen 
      Often works like INPUT command in other languages
  Command button
    Main Property:  Caption
    Main Event:  Click
    Main Uses:  
      Indicates user's desire to do something.  
      Frequently house significant amounts of program code
      Graphically shows being depressed
      Easily recognized as something to click on
  Scroll Bar
    Main Property:  Value
    Main Event:  Change
    Main Uses:
      Allows the user to input a numeric value graphically
      Range can be determined at design time
      Allows little opportunity for error
  Option Button
    Main Property:  Value (True or False)
    Main Event:Click    
    Main Uses:
      Allows user to check ONLY ONE of a series of options
      Grouped in a form or frame
      When one in a group is true,  all others are false
      Like a car radio 
  Check Box
    Main Property: Value (Checked, Unchecked, or Greyed)
    Main Event:  Click
    Main Uses:
      Allows user to check one OR MORE of a series of options
      Can also be grouped
      More than one can be checked at a time

Your program - The VB Sampler

Purpose: This program should show that you have a working knowledge of a number of simple VB controls. You will also practice creating a program, placing controls on the form, changing a few properties, and writing simple code.
Description:
The program will show the user a sample form, and each time they click on a control, they will see what kind of an object it is.

The form:
  Open VB and change the default form's name to SAMPLER
  Change the form's CAPTION to "{your name}'s VB Sampler"
  Add various controls to make your form look something like this:

[picture of form]

  Make an output window:
    Label1 is where we will print stuff for the user to see.
    We will be referring to this label aa lot in our code, so we need 
    to give it a meaningful name
    Click on the label, then go to the properties box
    Change the Name property to LblOutput
    Note the Lbl prefix denotes this object a label
    Also notice use of upper case
  Change the typeface  characteristics of the label:
    Change the FontName property to Arial
    Change the FontSize to 15
    Change the Alignment to Centered
    Change the Caption to {nothing}
  Adding some code:
    Picture box:
      Double - Click on the picture box to get to its code window.
      Note that we are dealing with the click event
      This is the default event for most objects.
      Write a line of code that sets the caption of the output label 
	to "Picture box"
	Hint==>  LblOutput.Caption = "Picture Box"
      Save as sampler.frm and VB2.MAK and test
  Label2, Command1, Option buttons, and Check boxes:
    Repeat the procedure you used to make the picture box code work
    (except of course you on't always say "Picture box")
  Text1:
    Text boxes don't default to the click event
    Double click on the text box to get the code window
    Notice that we are in the CHANGE event.
    Use the PROC list box at the top of the code window to change 
      to the Click event
    Write the same type of code you used for the other events
  Form:
    Double - click on the form (outside the controls) to get to the 
      form's code window
    Notice that the form's default event is load
    Use the PROC list box at the top of the code window to change to 
      the Click event
    Again write the same type of code you have been doing
  Scroll Bar:
    This control doesn't have a click event
    Go ahead and use the Change event as it is the default
    Write the following code:
    LblOutput.Caption = "Scroll Bar: " & HScroll1.Value
    This prints out the phrase "Scroll Bar:" and adds the current value 
      of the scroll bar
  Quit Button:
    Change the caption of Command2 to "Quit"
    Double click to get to the code window
    type End
Save and test
Return to syllabus.