|
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/ Quiz #2 Due Thursday, April 20, 2006
I. Definitions
1. delegate signature (p. 458-459)
A signature for a method includes its name, number of
parameters, and parameter types. The signature of a
method does not include its return type. Like methods,
a delegate may include a return type or the keyword
void as part of its heading. However, unlike a method,
the return type of a delegate becomes part of its
identifying signature.
Note:
A delegate is implemented in C# as a class. However, an
instance of the delegate class is also referred to as
a delegate, rather than as an object. The fact that both
the class type and the instance type go by the name
delegate can be confusing.
2. Control class (p. 403, 407-425)
The System.Windows.Forms namespace includes many classes
that we can add to our form, representing controls with
names such as Button, Label, TextBox, ComboBox, ListBox,
CheckBox, RadioButton, etc.
All of the control classes that can be added to a form are
derived from the System.Windows.Forms.Control class. With
Object being the base class from which all classes
ultimately are derived, all Windows control classes derive
from the class named Control.
3. Toolbox
The C# Toolbox includes icons that allow the programmer to
add various controls to a GUI form, such as Buttons, Labels,
TextBoxes, ComboBoxes, ListBoxes, CheckBoxes, RadioButtons,
etc.
4. MainMenu control (p. 482-485)
In C#, we can add menus to an application. Menus offer the
advantage of taking up minimal space on the window. A number
of classes are available that inherit from the Menu class.
One of the classes is the MainMenu class. Using the Visual
Studio .NET Toolbox window, it is easy to drag and drop a
MainMenu control object to the window form. The menu
structure is created by typing the text for the menu option
in the prompted text box. Additional drop-down options can
be typed from the lower layers so that we can create a menu
structure like we see in GUI applications such as a word-
processing program.
5. location property of a control (p. 396, 407)
The location property contains an X and a Y coordinate that
specify the location of the uppermost top-left position of
the control in the application form window.
This property Gets or Sets the coordinates of the upper-left
corner of the control relative to the upper-left corner of
its container.
6. TabIndex property (p. 407, 416-417)
The tab order is the order in which controls will receive
"focus" as the user repeatedly presses the tab key.
By default, the tab order is the same order as the order in
which controls are added to the form.
Selecting ViewTabOrder from the View menu shows this
sequential order. The programmer can change this order at
design time, in order to meet their needs.
This property Gets or Sets the tab order of the control
within its container.
7. Focus method (p. 408)
Only one object (control) can have "focus" within a form,
at any instance in time. When the user interacts with the
form, the control that has focus will receive the input
from the user, such as a mouse click or entering text
into a text box, etc.
Focus can be advanced by pressing the tab key, in which
case focus progresses from one control to the next,
according to the "tab index" order (see item 6. above).
Focus can also be controlled by the user, by clicking the
mouse pointer on a control of their choice.
And focus can be specified under program control by using
the "Focus()" method, such as:
txtBox1.Focus();
II. Questions or short essay:
1. What is the purpose of the Items property of a ListBox?
(p. 465, 472)
The Items property is used to set the initial values
for the list box. For example:
this.lstBox1.Items.AddRange(new object[]
{ "Milk", "Eggs", "Orange Juice", "Apples" } );
2. What is the default event for a ComboBox? (p. 479)
As with the ListBox control object, the default event-
handler method for ComboBox is SelectedIndexChanged().
3. What is the purpose of putting the "&" character in the
text that appears in a menu item? (p. 483)
With most Windows applications, shortcuts are available
for selections. When we type the text that is to appear
in the menu, preceding a character with an ampersand (&)
places an underline under the next character typed. For
example, if we type &File, then Alt-F becomes the
shortcut for File, and we will see the word File (with
letter F underlined) displayed when we press the Alt key.
4. Describe two Predefined Standard Windows dialog Boxes
that could be added to your form.
a. TextBox (p. 412-416)
The user can enter text information into a textbox
during program execution. The program can access this
text, by using program code such as:
strText = txtBox1.Text;
b. ListBox (p. 464-499)
The user can click the mouse on a listbox entry of
their choice. This will fire a SelectedIndexChanged()
event, at which time the user can determine which item
was selected from the items in the listbox list, such
as:
strItem = lstBox1.SelectedItem.ToString();
5. Why might you set the multiline property of a text box
to true? (p. 412-413)
Normally, a single line of text is shown in the text box
object. However, by changing the multiline property to
true, the textbox object can show several lines of text.
The multiline property can also be used in conjunction
with the ScrollBars property to designate whether vertical
and/or horizontal scrollbars are added.
Also, the multiline property must be set to false when the
PasswordChar property is used with a textbox.
6. What is the default event handler for CheckBox objects?
(p. 499-500)
The default event handler method for CheckBox objects
is CheckChanged();
7. Why is it usually better to associate only one event
method with all of the check boxes in a group of check
boxes on a form?
Re: Check boxes
The event handler can use a series of nested "if" tests
on individual check box control names, in order to
determine which check box(es) are currently checked.
This way, only one event handler is needed to handle
the events for a group of check boxes.
Alternatively, the check boxes will be members of a
checkbox collection. By accessing the members of the
collection, the program can determine which check box
raised the event.
Re: Radio buttons
This concept is even more important, and more applicable,
for a group of radio buttons, because radio buttons in a
GroupBox group are mutually exclusive. This means that
only one radio button is allowed to be true at any one
point in time. So, when an event handler finds a true
radio button control, all remaining radio buttons in the
group must be false, and the program does not need to
examine all remaining radio buttons in the common radio
button group.
III. Programming Exercises: Write source code for the following:
Create an order form that allows bags to be purchased. There
are six different types: full decorative, beaded, needlepoint
design, fringed, fringed beaded, and plain. Create a ListBox
object for the different styles. After the user makes a
selection, display a message indicating which selection was
made. Add to the application by including a control that
allows the user to enter the quantity desired. Include a set
of radio buttons that contain shipping options of overnight,
three day, and standard. The price for each bag is as follows:
full decorative $50, beaded $45, needlepoint $40, fringed $25,
fringed beaded $50, and plain $20. The shipping charges are
based on the total purchase. The following percentages are
used: overnight 10%, three day 7%, and standard 5%. Display
in a message box the shipping charge along with the selection,
quantity, and total cost.
Turn in your source code for this program.
|