|
There are various small but effective techniques you can use to provide help in your
application: never neglect help.
|
Practical
Learning: Introducing Help
|
|
- Start Microsoft Visual C#
- Create a Windows Application named ClarksvilleIceCream1
- In the Properties window, change the form's Text to Clarksville Ice
Cream
- Design the form as follows:
 |
| Control |
Name |
Text |
Additional Properties |
| GroupBox |
grpIceCream |
|
|
| Label |
|
Order Date: |
|
| DateTimePicker |
dtpOrderDate |
|
Format: Short |
| Label |
|
Order Time: |
|
| DateTimePicker |
dtpOrderTime |
|
Format: Time
ShowUpDown: True |
| Label |
|
Flavor: |
|
| ComboBox |
cboFlavors |
|
|
| Label |
|
Container: |
|
| ComboBox |
cboContainers |
|
|
| Label |
|
Ingredient: |
|
| ComboBox |
cboIngredients |
|
|
| Label |
|
Scoops: |
|
| TextBox |
txtScoops |
1 |
TextAlign: Right |
| Label |
|
Order Total: |
|
| TextBox |
txtOrderTotal |
0.00 |
TextAlign: Right |
| Button |
btnNewOrder |
New Order |
|
| Button |
btnCalcTotal |
Calculate Total |
|
| Button |
btnClose |
Close |
|
|
- Click the combo box to the right of the Flavor label. Then, in the
Properties, click the ellipsis button
of Items property and create the list with:
Vanilla
Cream of Cocoa
Chocolate Chip
Cherry Coke
Butter Pecan
Chocolate Cookie
Chunky Butter
Organic Strawberry
Chocolate Brownies
Caramel Au Lait |
- Click OK
- Click the combo box to the right of the Container label. Then, in
the Properties, click the ellipsis button
of Items property and create the list with:
- Click OK
- Click the combo box to the right of the Ingredient label. Then, in
the Properties, click the ellipsis button
of Items property and create the list with:
None
Peanuts
Mixed Nuts
M & M
Cookies |
- Click OK
- Double-click the New Order button to access its Click event and
implement it as follows:
private void btnNewOrder_Click(object sender, EventArgs e)
{
// If the user clicks New Order, we reset the form with the default values
this.dtpOrderDate.Value = DateTime.Today;
this.dtpOrderTime.Value = DateTime.Now;
this.cboFlavors.Text = "Vanilla";
this.cboContainers.Text = "Cone";
this.cboIngredients.Text = "None";
this.txtScoops.Text = "1";
this.txtOrderTotal.Text = "0.00";
}
|
- Return to the form
- Double-click the Calculate Total button to access its Click event
- Implement it as follows:
private void btnCalcTotal_Click(object sender, EventArgs e)
{
double PriceContainer = 0.00,
PriceIngredient = 0.00,
PriceScoops = 0.00,
OrderTotal = 0.00;
int NumberOfScoops = 1;
// Find out what container the customer requested
// The price of a container depends on which one the customer selected
if( cboContainers.Text == "Cone" )
PriceContainer = 0.55;
else if( cboContainers.Text == "Cup" )
PriceContainer = 0.75;
else
PriceContainer = 1.15;
// If the customer selected an ingredient, which is not "None", add $.95
if( cboIngredients.Text != "None" )
PriceIngredient = 0.95;
try {
// Get the number of scoops
NumberOfScoops = int.Parse(this.txtScoops.Text);
if( NumberOfScoops == 2 )
PriceScoops = 2.55;
else if( NumberOfScoops == 3 )
PriceScoops = 3.25;
else
PriceScoops = 1.85;
}
catch(FormatException)
{
MessageBox.Show("The value you entered for the scoops is not valid" +
"\nOnly natural numbers such as 1, 2, or 3 are allowed" +
"\nPlease try again");
}
// Make sure the user selected a flavor,
// otherwise, there is no reason to process an order
if( cboFlavors.Text != "" )
OrderTotal = PriceScoops + PriceContainer + PriceIngredient;
this.txtOrderTotal.Text = OrderTotal.ToString();
}
|
- Return to the form
- Double-click the Close button and implement its Click event as
follows:
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
|
- Test the application. Here is an example:
- Close the form and return to Visual Studio
One way you can provide simple help consists
of displaying short indicative messages on a status bar. To do this, you
can first create sections, called panels, on a status bar and then display
the necessary messages in the section of your choice. The message can be
anything but it should consist of just a few words to fit in its section
without going over board.
|
Practical
Learning: Helping Through a Status Bar
|
|
- Display the from and expand its bottom border a little bit
- On the Toolbox, click StatusStrip and click the bottom section of the
form
- In the Properties window, click Items and click its ellipsis button

- In the Select Item and Add to List Below combo box, select
StatusLabel if necessary and click Add
On the right side, set the Text to Ready

- Click OK

- On the form, click the dtpOrderDate control; that is, the combo box
on the right side of the Order Date label
- In the Properties window, click the Events button
and double-click MouseMove
- Return to the form
- In the same way, initiate the MouseMove event of the dtpOrderTime
date time picker, the cboFlavors combo box, the cboContainers combo
box, the cboIngredients combo box, the txtScoops text box, the
txtOrderTotal text box, and the form
- Implement the events as follows:
private void dtpOrderDate_MouseMove(object sender, MouseEventArgs e)
{
statusStrip1.Items[0].Text =
"Specify the date this order was processed";
}
private void dtpOrderTime_MouseMove(object sender, MouseEventArgs e)
{
statusStrip1.Items[0].Text =
"Specify the time this order was processed";
}
private void cboFlavors_MouseMove(object sender, MouseEventArgs e)
{
statusStrip1.Items[0].Text = "Select the customer's desired flavor";
}
private void cboContainers_MouseMove(object sender, MouseEventArgs e)
{
statusStrip1.Items[0].Text =
"Select the type of object that will contain the ice cream";
}
private void cboIngredients_MouseMove(object sender, MouseEventArgs e)
{
statusStrip1.Items[0].Text =
"Select an ingredient to spice the ice cream";
}
private void txtScoops_MouseMove(object sender, MouseEventArgs e)
{
statusStrip1.Items[0].Text =
"Select the number of scoops to fill the container";
}
private void txtOrderTotal_MouseMove(object sender, MouseEventArgs e)
{
statusStrip1.Items[0].Text =
"This displays the total of the order";
}
|
- Return to the form and click a border of the group box
- In the Events section of the Properties, generate the event of the
MouseHover field, and implement it as follows:
private void grpIceCream_MouseHover(object sender, EventArgs e)
{
this.statusStrip1.Items[0].Text = "Ready";
}
|
- Return to the form and click an area of its body away from any
control on it
- In the Events section of the Properties, generate the event of the
Move field, and implement it as follows:
private void grpIceCream_MouseHover(object sender, EventArgs e)
{
this.statusStrip1.Items[0].Text = "Ready";
}
|
- Test the application

- After using it, close the form and return to Visual Studio
A tool tip is a small yellow box that displays a
word or a group of words when the user positions the mouse on top of a
control:
To create a tool tip system in a Visual Studio 2005 application, first add a ToolTip control to a form. After adding a ToolTip
control, the form and all controls on it receive a new field in
the Properties window. If the new ToolTip control is called ToolTip1, the
new field in the Properties window for each control is ToolTip on
ToolTip1. To display a tool tip for a control, first click it on the form.
Then, in the Properties window, click ToolTip on ToolTip1, and type the
desired tool tip.
|
Practical
Learning: Adding Tool Tips
|
|
- To prepare for tool tips, on the Toolbox, click ToolTip
and click
the form
- On the form, click each control and, in the Properties window, set
its ToolTip On ToolTip property as follows:
| Control |
ToolTip On ToolTip1 |
| dtpOrderDate |
Click the arrow to select a date |
| dtpOrderTime |
Click each section, then click one of the arrows
to change its value |
| cboFlavors |
Click the arrow to display a list, then select a
flavor from the list |
| cboContainers |
Click to display the list of containers and select
one |
| cboIngedients |
Display the list of ingredients and make the
customer's choice |
| txtScoops |
Enter the number of scoops (1, 2, or 3) to fill
the container |
| txtOrderTotal |
This displays the total amount of this order |
| btnNewOrder |
Click here to reset the form |
| btnCalcTotal |
Click here to calculate the total of the order |
| btnClose |
Click here to Close the form |
- Test the application

- Close it and return to Visual Studio
|
|