|
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 #6 Due Thursday, April 13, 2006
I. Definitions -- Please explain the following terms:
1. delegate (p. 458, 797)
Delegates are special types of .NET classes whose instances
store references (addresses) to methods as opposed to storing
actual data.
2. event wiring (p. 799)
Associating a method in a program to an event, such as the
user clicking a button. The method is automatically called
when the event occurs.
3. ListBox (p. 464-477)
The ListBox control is a Windows form control component.
ListBox controls can be used to display a list of items from
which the user can make single or multiple selections.
ListBox controls are derived from the
System.Windows.Forms.ListControl class.
4. CheckBox (p. 499-500)
A CheckBox control is a Windows form control component.
It can either be "checked" (true) or "unchecked" (false).
5. RadioButton (p. 503-514)
A RadioButton control is a Windows form control component.
It can be either "selected" (true) or "unselected" (false).
RadioButtons can be grouped, so that only one radiobutton
in the group can be "true", i.e., the radiobuttons are
"mutually exclusive".
6. multicast delegate (p. 802)
A delegate is wired to more than one method. When the
multicast delegate is used, multiple methods are called
automatically, one afater the other. One requirement for
multicast delegates is that the return type be void.
7. GroupBox control (p. 503)
A GroupBox control can be placed on the form before you
add RadioButton objects. All RadioButton objects contained
within a GroupBox control will be mutually exclusive, that
is, C# .NET will only permit one of the RadioButtons to be
selected at one time.
Note: RadioButtons can also be placed on a Panel control
in order to provide a mutually exclusive logical grouping.
II. Questions or short essay
1. How are ComboBoxes different from ListBoxes?
(p. 464- 477, 478-9, p. 723-4)
In many cases, the ListBox and ComboBox controls can be
used interchangeably. They share many of the same properties
and methods because they are both derived from the
System.Windows.Forms.ListControl class.
A ListBox control is used to display a list of items from
which the user can make a single or multiple selection.
ComboBoxes are collapsed, and, thus, save space on a form.
When the user clicks on a ComboBox, it opens, displaying
the choices that it contains. When the user clicks on a
choice, that choice is displayed in the ComboBox text
window, and the ComboBox collapses once again.
The ComboBox also provides an option to allow the user
to key in their own data. For this case, a KeyPress()
event can be registered and used to detect when the user
enters their own data.
2. How do you design your form so that a group of radio buttons
will work correctly together? (p. 503)
You place a GroupBox or a Panel on the screen. Then you
create RadioButtons within the GroupBox or Panel. Then
C# will treat these RadioButtons as a mutually exclusive
logical group, from which only one radio button can be
selected at one time.
3. What two parameters are included in event-handler methods?
(p. 464)
Windows Form Events include "object sender" and "e", where
the first parameter "object sender" represents the source
that raised the event, and the second parameter "e" is the
data, such as error message information, for the event.
4. How do you add an item to a list box at run time? (p. 469-477)
The ListBox control can have values added or removed at
runtime. To add a value at runtime, you use the Add() method
with the Items property, as follows:
lstBoxEvents.Items.Add("item value to add");
5. What is the default event-handler method for a list box?
(p. 467)
The SelectedIndexChanged event is the default event. For
example:
private void listBox1_SelectedIndexChanged(object sender,
System.EventArgs e)
6. After you type the text for a menu, what else must be done
before the menu will be seen on a form? (p. 484)
After you type the text that will appear on the menu, you
must set the Menu property on the form to the name of the
MainMenu object. Otherwise, the menu does not display when
you launch the application.
7. What is a KeyPress() event? (p. 479-480)
A KeyPress() event occurs when the user presses a key.
Actually, the event is fired with each and every keystroke.
The KeyPress() event can be registered to respond to values
typed into the text portion of a control, such as the text
box of a ComboBox control.
III. Programming Exercise
Create the following program:
Programming exercise #6 on page 553:
Create a Windows application for purchasing carpet.
Allow the length and width of a room to be entered.
Have a control that displays different prices of carpet.
Include, for example, prices such as $21.95 per square yard.
After the users enter their room dimensions and the price of
the carpet, display the total cost to carpet the room.
Turn in your source code for this program.
|