ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 24 May 2017 My Price 11.00

Complete the following exercises using Visual Basic Express 2012

Hello, I have the book I downloaded from course hero. I was trying to download it from MYIT Statlab via e text but don't know how. Maybe you can tell how.

Anyway here is the question and attachments:

Question:

Complete the following exercises using Visual Basic Express 2012

From Visual Basic book - Chapter 2: 

Read chapter 2 and be sure to do all the tutorials from the very beginning of the chapter.

You must submit the following for grading:  

1.  Tutorial:   Focus on Problem Solving: Responding to Events - 10 points 

2.  Programming Challenge #6:  Clickable Images  - 10 points 

 

 

 

1/29/10 CHAPTER M02_GADD3409_05_SE_C02.qxd 2:46 PM 2 Page 43 Creating Applications
with Visual Basic TOPICS
2.1 Focus on Problem Solving: Building
the Directions Application 2.4 The AutoSize, BorderStyle, and
TextAlign Properties 2.2 Focus on Problem Solving:
Responding to Events 2.5 Displaying Message Boxes 2.6 Clickable Images 2.3 Modifying a Control’s Text
Property with Code 2.7 Using Visual Studio Help 2.8 Debugging Your Application In this chapter you will develop your first application, which displays a map and written
directions to the Highlander Hotel. This application uses a form with labels, a PictureBox
control, and buttons. You will write your first event handlers in Visual Basic code and then
you will learn to use the Label control’s AutoSize, BorderStyle, and TextAlign properties.
You will be introduced to clickable images, context-sensitive help, and the debugging
process. 2.1 Focus on Problem Solving:
Building the Directions Application
CONCEPT: In this section you create your first Visual Basic application:
a window that displays a map and road directions to a hotel. In the
process you learn how to place controls on a form and manipulate
various properties.
The desk clerks at the historic Highlander Hotel frequently receive calls from guests
requesting driving directions. Some desk clerks are not familiar with the street numbers
or exits, and inadvertently give unclear or incorrect directions. The hotel manager has
asked you to create an application that displays a map to the hotel. The desk clerks can 43 M02_GADD3409_05_SE_C02.qxd 44 Chapter 2 1/29/10 2:46 PM Page 44 Creating Applications with Visual Basic refer to the application when giving directions to customers over the phone. We will use
the following steps to create the application:
1.
2.
3.
4.
5. Clearly define what the application is to do.
Visualize the application running on the computer and design its user interface.
Determine the controls needed.
Define the values of each control’s relevant properties.
Start Visual Basic and create the forms and other controls. Now we will take a closer look at each of these steps.
1. Clearly define what the application is to do.
Purpose:
Input:
Process:
Output: Display a map to the Highlander Hotel
None
Display a form
Display on the form a graphic image showing a map 2. Visualize the application running on the computer
and design its user interface.
Before you create an application on the computer, first you should create it in your mind.
This step is the visualization of the program. Try to imagine what the computer screen
will look like while the application is running. Then draw a sketch of the form or forms
in the application. Figure 2-1 shows a sketch of the Directions form presented by this
application. Figure 2-1 Sketch of Directions form 3. Determine the controls needed.
In this step you list all the needed controls. You should assign names to all the controls
that will be accessed or manipulated in the application code and provide a brief description of each control. Our application needs only three controls, listed in Table 2-1. Because
none of the controls are used in code, we will keep their default names. M02_GADD3409_05_SE_C02.qxd 1/29/10 2:46 PM Page 45 2.1 Focus on Problem Solving: Building the Directions Application Table 2-1 Directions application controls
Control Type Control Name Description Form (Default Name: Form1) Label (Default Name: Label1) PictureBox (Default Name: PictureBox1) A small form that will serve as the window onto
which the other controls will be placed
Displays the message Directions to the Highlander
Hotel
Displays the graphic image showing the map to
the hotel 4. Define the values of each control’s relevant properties.
Each control’s property settings are listed in Table 2-2. Table 2-2 Directions application control properties
Property Value Form
Name Form1 Text Directions Label
Name Label1 Text Directions to the Highlander Hotel Font Microsoft sans serif, bold, 16 point PictureBox
Name PictureBox1 Image HotelMap.jpg SizeMode StretchImage Notice that in addition to the Name and Text properties, we are also setting the Font
property of the Label control. We will discuss this property in detail later.
In addition to its Name property, we are setting the PictureBox control’s Image and SizeMode properties. The Image property lists the name of the file containing the graphic
image. We will use HotelMap.jpg, which is located in the student sample programs folder
named Chap2. The SizeMode property is set to StretchImage, which allows us to resize
the image. If the image is too small, we can enlarge it (stretch it). If it is too large, we can
shrink it.
5. Start Visual Basic and create the forms and other controls.
Now you are ready to construct the application’s form. Tutorial 2-1 gets you started. 45 M02_GADD3409_05_SE_C02.qxd 46 Chapter 2 2/15/10 5:26 PM Page 46 Creating Applications with Visual Basic Tutorial 2-1:
Beginning the Directions application
In this tutorial you begin the Directions application. You will create the application’s
form and use the Properties window to set the form’s Text property.
Step 1:
Tutorial 2-1
Walkthrough Start Visual Studio (or Visual Basic Express), as you did in Chapter 1. Perform
one of the following actions to create a new project:
• On the Start Page click the New Project icon
• Click File on the menu bar and then select New Project...
• Press Ctrl+N on the keyboard
The New Project window will appear. If you are using Visual Studio, under
Installed Templates select Visual Basic. Then, in either Visual Studio or Visual
Basic Express select Windows Forms Application.
The default project name, such as WindowsApplication1, appears in the Name
text box. Replace this name with Directions. Click the OK button to close the
window. Step 2: The Visual Basic environment should be open with a blank form named
Form1 in the Designer window, as shown in Figure 2-2. Click the form to
select it. Figure 2-2 Form1 displayed in the Designer window Step 3: Look at the Properties window. It should appear as shown in Figure 2-3.
Because you have selected Form1, the Properties window displays the properties
for the Form1 object. The drop-down list box at the top of the window shows M02_GADD3409_05_SE_C02.qxd 1/29/10 2:46 PM Page 47 2.1 Focus on Problem Solving: Building the Directions Application the name of the selected object, Form1. Below that, the object’s properties are
displayed in two columns. The left column lists each property’s name and the
right column shows each property’s value. The area at the bottom of the Properties
window shows a brief description of the currently selected property.
TIP: The Properties window has two buttons near the top that control the
order of names in the window. The first ( ) sorts by category and the second
( ) sorts alphabetically. We will use the alphabetical sort in our examples.
The Text property is highlighted, which means it is currently selected. A form’s
Text property holds the text displayed in the form’s title bar. It is initially set to
the same value as the form name, so this form’s Text property is set to Form1.
Follow the instructions in Steps 4 and 5 to change the Text property to
Directions.
Step 4: In the Properties window, double-click the word Form1 inside the Text
property. Step 5: Delete the word Form1 and type Directions in its place. Press the e key.
Notice that the word Directions now appears in the form’s title bar.
N O T E : Remember, changing a form’s Text property changes only the text
that is displayed in the form’s title bar. The form’s name is still Form1. Step 6: Perform one of the following actions to save the project:
• Click the Save All button ( )on the standard toolbar
• Click File on the menu bar and then select Save All
• Press Ctrl+Shift+S on the keyboard
Because this is the first time you have saved the project, you will see the Save
Project window. In that window, click the Save button to save the project at the
specified location. Then, leave Visual Studio running for Tutorial 2-2, which
takes you through the process of adding a Label control to the form. Figure 2-3 Properties window showing Form1
Name of the
selected object Text property Property
description 47 M02_GADD3409_05_SE_C02.qxd 48 Chapter 2 1/29/10 2:46 PM Page 48 Creating Applications with Visual Basic Tutorial 2-2:
Adding a Label control to the Directions application
Step 1: Tutorial 2-2
Walkthrough Now you are ready to add the Label control to the form. Make sure the
Common Controls tab is open in the Toolbox window, as shown in Figure 2-4,
and double-click the Label control icon. The label appears on the form with a
dotted line around it and a small white square in its upper left corner, as shown
in Figure 2-5. The dotted-line rectangle is called a bounding box—it marks the
tightest rectangle that contains all parts of the control. Figure 2-4 Label control tool Step 2: Figure 2-5 Label control on form Look at the Properties window. Because the label you just placed on the form is
currently selected, the Properties window shows its properties (see Figure 2-6).
The Text property is set, by default, to Label1. Double-click this value to select
it, and replace its value by typing Directions to the Highlander Hotel
in its place. Press the e key. When you have typed the new text into the Text
property, the form appears, as shown in Figure 2-7. The label resizes itself to fit
the contents of the Text property. M02_GADD3409_05_SE_C02.qxd 1/29/10 2:46 PM Page 49 2.1 Focus on Problem Solving: Building the Directions Application Figure 2-6 Properties window Step 3: Figure 2-7 Label with new text property value Next, you will move the label to a new location on the form. Move the mouse
over the label on the form. Notice that when the mouse pointer is over
the label, it becomes a four-headed arrow ( ). Hold down the left mouse
button, and drag the label to the top middle area of the form, as shown in
Figure 2-8. From now on, we will refer to this type of operation as dragging
the control. Figure 2-8 After moving the Label control Step 4: Save the project. Leave Visual Studio running for Tutorial 2-3, which takes you
through the process of changing the Label control’s font size and style. 49 M02_GADD3409_05_SE_C02.qxd 50 Chapter 2 1/29/10 2:46 PM Page 50 Creating Applications with Visual Basic Tutorial 2-3:
Changing the Label’s font size and style
In the planning phase, we indicated that the label’s text should be displayed in a 16-point
bold Microsoft sans serif font. These characteristics are controlled by the label’s Font property. The Font property allows you to set the font, font style, and size of the label’s text. In
this tutorial you will use the Font property change the appearance of the label’s text.
Tutorial 2-3
Walkthrough Step 1: With the Label selected, click the Font property in the Properties window.
Notice that an ellipsis button ( ) appears. When you click the ellipsis button,
the Font dialog box appears, as shown in Figure 2-9. Figure 2-9 Font dialog box Step 2: Microsoft Sans Serif is already the selected font. Click Bold under Font style,
and select 16 under Size. Notice that the text displayed in the Sample box
changes to reflect your selections. Click the OK button.
The text displayed by the label is now in 16-point bold Microsoft sans serif.
Unfortunately, not all of the label can be seen because it is too large for the
form. You must enlarge the form so the entire label is visible. Step 3: Select the form by clicking anywhere on it, except on the Label control. You will
know you have selected the form when a thin dotted line with sizing handles
appears around it. The dotted line is the form’s bounding box, and the sizing
handles are the small boxes, shown in Figure 2-10, that appear on the form’s
right edge, lower right corner, and bottom edge. Step 4: Position the mouse pointer over the sizing handle that appears on the form’s
right edge. As shown in Figure 2-11, the mouse pointer becomes a two-headed
arrow ( ). Click and drag the sizing handle to widen the form. Then, select
the label and move it so it appears similar to Figure 2-12. M02_GADD3409_05_SE_C02.qxd 2/9/10 11:31 AM Page 51 2.1 Focus on Problem Solving: Building the Directions Application Figure 2-10 The form selected, with sizing handles shown Sizing handle Sizing handle
Sizing handle Figure 2-11 The mouse pointer positioned over the form’s right edge sizing handle Figure 2-12 The form widened and the label repositioned Step 5: Save the project. Leave Visual Studio running for Tutorial 2-4, which takes you
through the process of deleting a control. 51 M02_GADD3409_05_SE_C02.qxd 52 Chapter 2 1/29/10 2:46 PM Page 52 Creating Applications with Visual Basic Tutorial 2-4:
Deleting a control
Sometimes you will find it necessary to delete a control that you have placed on a form.
To delete a control, select it and press the ∂ key on the keyboard. In this tutorial you
will add another Label control to the form (one that you will not need) and then delete it.
Step 1: Double-click the Label icon in the Toolbox. Another Label control appears on
the form. Step 2: With the new Label control still selected, press the ∂ key on the keyboard.
The label is deleted from the form.
The last step in building this application is to insert the street map. In Tutorial 2-5
you insert a PictureBox control, which can be used to display an image. The PictureBox Control
If you want to display a graphic image on an application’s form, you use a PictureBox control. A PictureBox control can display images that have been saved in the bitmap, GIF,
JPEG, metafile, or icon graphics formats. When a PictureBox control is placed on a form, it
appears as an empty rectangle in which the image will be displayed. You can adjust the PictureBox control’s size to make the image any size that you want.
The PictureBox control has several properties, but the following two properties are of
particular interest:
• The Image property specifies the image file that is to be displayed by the control.
• The SizeMode property specifies how the image is to be displayed. It can be set to
one of the following values:
• Normal
This is the default value. The image will be positioned in the upper-left corner of
the PictureBox control. If the image is too big to fit in the PictureBox control, it
will be clipped.
• StretchImage
The image will be resized both horizontally and vertically to fit in the PictureBox
control. If the image is resized more in one direction than the other, it will appear
stretched.
• AutoSize
The PictureBox control will be automatically resized to fit the size of the image.
• CenterImage
The image will be centered in the PictureBox control, without being resized.
• Zoom
The image will be uniformly resized to fit in the PictureBox without losing its
original aspect ratio. (Aspect ratio is the image’s width to height ratio.) This
causes the image to be resized without appearing stretched.
In Tutorial 2-5 you will place a PictureBox control on the application’s form and set the
control’s properties so it displays the street map image. M02_GADD3409_05_SE_C02.qxd 1/29/10 2:46 PM Page 53 2.1 Focus on Problem Solving: Building the Directions Application Tutorial 2-5:
Inserting a PictureBox control
Step 1: Locate the PictureBox icon in the Toolbox. You will find it in the Common
Controls group. (The tools are listed in alphabetical order.) When you locate the
PictureBox tool, double-click it.
An empty PictureBox control appears on the form. Move the control to a position approximately in the center of the form, as shown in Figure 2-13. Tutorial 2-5
Walkthrough Figure 2-13 PictureBox control placed Step 2: Now you will specify the image that the PictureBox control will display. Locate
the PictureBox control’s Image property in the Properties window. The Image
property is currently set to (none), which means that no image is displayed.
Click the property and notice that a browse button ( ) appears next to the
property setting. Click the browse button. The Select Resource window, shown
in Figure 2-14 should appear. Step 3: As indicated in Figure 2-14, in the Select Resource window select Local
Resource, and then click the Import button. When the Open dialog box
appears, navigate to the folder on your computer where the student sample files
are located. Then, in the Chap2 folder select the file named HotelMap.jpg. After
you click the OK button, you should see the graphic shown in the Select
Resource window, as shown in Figure 2-15. Click the OK button to accept the
image, and you will see it displayed in the PictureBox control.
Your form should appear similar to Figure 2-16. As you can see from the figure,
only part of the image is displayed. This is because the PictureBox control is
smaller than the image, and the SizeMode property is set to its default value,
Normal. 53 M02_GADD3409_05_SE_C02.qxd 54 Chapter 2 1/29/10 2:46 PM Page 54 Creating Applications with Visual Basic Figure 2-14 The Select Resource window 1 Select Local Resource 2 Click Import Figure 2-15 The HotelMap.jpg file selected Figure 2-16 The HotelMap.jpg image partially displayed in the PictureBox control M02_GADD3409_05_SE_C02.qxd 1/29/10 2:46 PM Page 55 2.1 Focus on Problem Solving: Building the Directions Application Step 4: Make sure the PictureBox control is selected, and locate the SizeMode property
in the Properties window. Notice that the SizeMode property is currently set to
Normal. When you click the SizeMode property in the Properties window, a
down arrow ( ) appears next to the property value.
Click the down arrow and a drop-down list appears, as shown in Figure 2-17.
The list shows all of the possible values for the SizeMode property. Select Zoom
from the list. This setting will resize the image so it fits within the bounding box
of the PictureBox control, without losing the image’s original aspect ratio.
(In other words, the image will not appear stretched.) Figure 2-18 shows an
example of how the form will appear. Figure 2-17 A drop-down list
showing the possible values of
the SizeMode property Step 5: Figure 2-18 The image resized uniformly Although the image has been resized, the PictureBox shown in our example
(in Figure 2-18) is too small. You can use the PictureBox’s sizing handles to
resize the PictureBox control so the image is displayed at the desired size. Resize
and move the PictureBox control so the form appears similar to Figure 2-19. 55 M02_GADD3409_05_SE_C02.qxd 56 Chapter 2 1/29/10 2:46 PM Page 56 Creating Applications with Visual Basic Figure 2-19 The PictureBox control resized Step 6: Save the project. Leave Visual Studio running for Tutorial 2-6, which takes you
through the process of compiling and running the application. NOTE: You have now seen that properties are set in the Properties window in one of
three ways:
• Typing a value for the property
• Selecting a value for the property from a drop-down list by clicking the downarrow button ( )
• Establishing a value for the property with a dialog box, which appears when
the Browse button ( ) is clicked Design Mode, Run Mode, and Break Mode
Visual Basic has three modes in which it operates as you develop and test an application.
The three modes are design mode, run mode, and break mode. You have already experienced design mode. This is the mode in which you create an application. When you are
placing controls on an application’s form or writing Visual Basic code, Visual Basic is operating in design mode. (Design mode is also known as design time.)
When you are ready to run an application that you are developing, you can execute it without leaving the Visual Studio environment. This puts Visual Basic in run mode (also known
as runtime). The application will be running on the computer, and you can interact with it
as the user. There are three ways to run an application from the Visual Studio environment:
• Click the Start Debugging button ( ) on the toolbar
• Click Debug on the menu bar, then select Start Debugging
• Press the % key
When you perform one of these actions, the Visual Basic compiler will begin compiling
the application. If no errors are found, the application will begin executing and Visual
Basic will enter run mode. You will experience run mode in the next tutorial.
Break mode is a special mode that allows you to momentarily suspend a running application
for testing and debugging purposes. It is also the mode that Visual Basic enters when a running application encounters a runtime error. (Recall from Chapter 1 that a runtime error is
an error that occurs while a program is running.) We will discuss break mode in Chapter 3. M02_GADD3409_05_SE_C02.qxd 1/29/10 2:46 PM Page 57 2.1 Focus on Problem Solving: Building the Directions Application Closing a Project
To close the current project, click File on the menu bar, and then click Close Project. If you
have made changes to the project since the last time you saved it, you will see a window
similar to Figure 2-20 asking you if you want to save your changes. If you want to save
your changes (in most cases you do), click Yes.
Figure 2-20 Save changes window Tutorial 2-6:
Running the application
Step 1: Now you will run the Directions application. It doesn’t have any event handlers,
so it will display only the PictureBox and Label when it runs. Perform one of the
following actions to run the application:
• Click the Start Debugging button ( ) on the toolbar
• Click Debug on the menu bar, then select Start Debugging
• Press the % key Tutorial 2-6
Walkthrough
Step 2: The Visual Basic compiler will begin compiling the application. (Recall from
Chapter 1 that the compiler translates the application to executable code.) After
a few moments, the compiler will finish and the application will run. You
should see the application’s form appear on the screen, as shown in Figure 2-21. Figure 2-21 The application running 57 M02_GADD3409_05_SE_C02.qxd 58 Chapter 2 1/29/10 2:46 PM Page 58 Creating Applications with Visual Basic Step 3: Now you will stop the application (end its execution). Perform one of the following actions:
• Click the Close button (
) on the application window
• Click Debug on the Visual Studio menu bar, then select Stop Debugging
• Press Ctrl+Alt+Break on the keyboard
The application will stop and Visual Studio will return to Design mode. Step 4: If you have not recently saved the project, do so now. Then, close the project. TIP: Save your work often to prevent the accidental loss of changes you have made to
your project. Checkpoint
2.1 You want to change what is displayed in a form’s title bar. Which of its properties
do you change?
2.2 How do you insert a Label control onto a form?
2.3 What is the purpose of a control’s sizing handles?
2.4 How do you delete a control?
2.5 What happens when you set a PictureBox control’s SizeMode property to
StretchImage?
2.6 What is the name of the dotted-line rectangle surrounding the Label control
when looking at a form in Design mode?
2.7 What are the three modes in which Visual Studio operates? How Solutions and Projects are Organized on the Disk
Now that you’ve created your first Visual Basic project, let’s take a look at the way the project’s files are organized on your computer’s disk. A solution is a container that holds Visual
Basic projects (see Figure 2-22). Each Visual Basic project must belong to a solution.
Although it is possible for a solution to hold more than one project, each project that you
will create in this book will be saved in its own solution. So, each time you create a new
project, you will also create a new solution to hold it. Figure 2-22 Organization of a solution and its projects
Solution Project 1 Project 2 Project 3 M02_GADD3409_05_SE_C02.qxd 1/29/10 2:46 PM Page 59 2.1 Focus on Problem Solving: Building the Directions Application When you save a project the first time, you see the Save Project window shown in
Figure 2-23. The window shows the project name, the location on the disk where the
project will be saved, and the solution name. By default the solution’s name will be the
same as the project’s name. Notice the Browse . . . button that appears next to the
location. You can click this button to select a different location, if you wish.
Also notice the Create directory for solution check box. It is a good idea to leave this box
checked. It causes a directory (folder) for the solution to be created at the specified location.
Inside that directory, another directory (folder) will be created for the project. Figure 2-23 The Save Project window Let’s use Figure 2-23 to see an example of how the files for the Directions project will be
organized on the disk. Notice that the location specified is:
C:\Users\Tony\Documents\Visual Studio 10\Projects At this location, a folder named Directions will be created to hold the solution. If we use
Windows to look inside that folder we will see that it contains the two...

Answers

(11)
Status NEW Posted 24 May 2017 01:05 AM My Price 11.00

-----------

Attachments

file 1495591037-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)