[FREE PDF sample] Advanced Programming Using Visual Basic 2008 4th Edition Julia Case Bradley ebooks
[FREE PDF sample] Advanced Programming Using Visual Basic 2008 4th Edition Julia Case Bradley ebooks
https://ebookfinal.com
https://ebookfinal.com/download/advanced-
programming-using-visual-basic-2008-4th-edition-
julia-case-bradley/
https://ebookfinal.com/download/clearly-visual-basic-programming-with-
microsoft-visual-basic-2010-2nd-edition-diane-zak/
ebookfinal.com
https://ebookfinal.com/download/simply-visual-basic-2008-with-dvd-
rom-3rd-ed-edition-deitel/
ebookfinal.com
https://ebookfinal.com/download/process-engineering-and-design-using-
visual-basic-second-edition-datta/
ebookfinal.com
https://ebookfinal.com/download/advanced-graphics-programming-using-
opengl-1st-edition-tom-mcreynolds/
ebookfinal.com
Practical Database Programming with Visual Basic NET 1st
Edition Ying Bai
https://ebookfinal.com/download/practical-database-programming-with-
visual-basic-net-1st-edition-ying-bai/
ebookfinal.com
https://ebookfinal.com/download/practical-database-programming-with-
visual-basic-net-2nd-edition-ying-bai/
ebookfinal.com
https://ebookfinal.com/download/numerical-simulations-and-case-
studies-using-visual-c-net-1st-edition-shaharuddin-salleh/
ebookfinal.com
https://ebookfinal.com/download/microsoft-visual-basic-net-
programming-for-the-absolute-beginner-1st-edition-jonathan-s-harbour/
ebookfinal.com
https://ebookfinal.com/download/microsoft-visual-basic-game-
programming-for-teens-2nd-edition-jonathan-s-jonathan-s-harbour-
harbour/
ebookfinal.com
Advanced Programming Using Visual Basic 2008 4th
Edition Julia Case Bradley Digital Instant Download
Author(s): Julia Case Bradley, Anita Millspaugh
ISBN(s): 9780073517223, 0073517224
Edition: 4
File Details: PDF, 18.42 MB
Year: 2009
Language: english
Computer and Information Technology
Bradley−Millspaugh
McGraw-Hill
=>?
McGraw−Hill Primis
ISBN−10: 0−39−012228−9
ISBN−13: 978−0−39−012228−5
Text:
http://www.primisonline.com
Copyright ©2009 by The McGraw−Hill Companies, Inc. All rights
reserved. Printed in the United States of America. Except as
permitted under the United States Copyright Act of 1976, no part
of this publication may be reproduced or distributed in any form
or by any means, or stored in a database or retrieval system,
without prior written permission of the publisher.
Contents
Front Matter 1
Preface 1
To the Student 9
6. Services 259
Text 259
iii
9. Reports 413
Text 413
iv
Bradley−Millspaugh: Front Matter Preface © The McGraw−Hill 1
Advanced Programming Companies, 2010
Using Visual Basic 2008
PREFACE
Visual Basic (VB) has become the most popular programming language for
several reasons. VB is easy to learn, which makes it an excellent tool for un-
derstanding programming concepts. In addition, it has evolved into such a
powerful and popular product that skilled Visual Basic programmers are in
demand in the job market.
Visual Basic 2008, the latest version of VB, has many new features, espe-
cially in queries and Web application development. Visual Basic is designed
to allow the programmer to develop applications that run under Windows
and/or in a Web browser without the complexity generally associated with
programming.
This edition of the text is updated to Visual Studio 2008, .NET 3.5, and
ASP.NET 3.5. The screen captures are based on Windows Vista, but all pro-
grams can be run in Windows XP, although the special effects of WPF cannot
be seen in XP.
Approach
Chapter topics are presented in a sequence that allows the programmer to learn
how to deal with a visual interface while acquiring important programming
skills such as accessing and updating data in a relational database, developing
applications for the Web and for mobile devices, and adding browser-based
Help files to an application.
The chapters may be used in various sequences to accommodate the needs
of the course, as well as a shorter quarter system or a semester-long course.
Pub ID: Pub_idTextBox 7. Retrieve and display an array of child rows for a selected parent row.
Hire Date: Hire_dateTextBox
8. Create an application that displays data from a many-to-many relationship.
9. Select the correct locations for handling and formatting data in a multitier application.
Plan the Objects, Properties, and Methods Plan the two tiers. Determine the
objects and property settings for the form and its controls and for the data-tier
component. Figure 3.31 shows a diagram of the components in the two tiers.
Presentation Tier
EmployeeForm Name
Text
EmployeeForm
Employees Learning Objectives
FullNameComboBox Name FullNameComboBox
Text boxes for all database
fields (including Hire Date)
Specific objectives tell students what
will be covered in the chapter and
what they will be able to do after
completing the chapter.
TIP
➤ Feedback 4.2 If the drop-down arrows do not
1. What Fill method statements are created for a relationship for appear in the Data Sources window,
Customers and Orders? Assume that the project contains two make sure that you have a form
TableAdapters called CustomersTableAdapter and OrdersTableAdapter displaying in the designer. ■
as well as a DataSet called NorthwindDataSet.
2. How can you view the relationship between two tables?
3. Describe the necessary steps to display the job description from the
jobs table rather than the job id when displaying the employee table.
TIPs
Feedback Questions Tips, found in the margins throughout
the text, help students avoid potential
Feedback questions encourage students to reflect on trouble spots in their programs and
the topics covered and evaluate their understanding of encourage them to develop good
details relating to that topic. programming habits.
Bradley−Millspaugh: Front Matter Preface © The McGraw−Hill 3
Advanced Programming Companies, 2010
Using Visual Basic 2008
Case Studies files have the same name, you are prompted to select the file to keep. A check
box allows you to show the deleted files since the last copy operation.
See “How to: Copy Web Site Files with the Copy Web Site Tool” in MSDN for
steps to copy all files at once, copy files individually, or synchronize files.
Claytor’s Cottages
Modify your Claytor’s Cottages case study project to the room has a Jacuzzi, Private access, and/or Fire-
Publishing a Web Site
display the room information. The Room form should place. Display the Bed type and the room rates from
display for the Edit / Rooms menu item. the Beds table. The Publish Web Site utility precompiles the Web pages and code content. The
On the Room form, include a combo box that Hint: You can bind the checked property of a compilation process removes the source code from the files and leaves only
holds the room name. Use check boxes to indicate if check box to a Boolean data field. stub files and compiled assemblies for the pages. You can specify the output
location as either a directory or a server location.
Precompiling the Web pages offers a couple of advantages over just copy-
ing the pages. One advantage is response speed. When pages are just copied to
Christian’s Car Rentals
a site, they must compile when a request is made for the page. Not having the
Modify your case study application to display the price and mileage rate in text boxes. The related mod- source code on the site also provides some security. During the publish pro-
vehicle information. Display a combo box that contains els and manufacturer should display in a grid. cess, you have the option of having markup protection, which does not allow for
the car sizes. When the user selects a size, display the later updates to the pages. If you opt to not have the files updatable, the code
in single-file pages is deployed as source code rather than being compiled into
an assembly.
vi P R E F A C E
Many topics from the introductory course are presented in greater detail
and demand more from the students. Many other advanced topics are pre-
sented, including displaying and updating relational databases, WCF Services,
data structures, user controls, Help files, and mobile application development
for Windows devices, along with expanded coverage of cascading style sheets
and AJAX for Web development.
This edition now includes coverage of the many new features in Visual
Studio including LINQ, WPF, and WCF. Both LINQ and WPF have been
placed in Chapter 13, the “Additional Topics” chapter, allowing you to cover
them at any point in the course.
The layout for Web pages uses the preferred method of incorporating <div>
for sections and all formatting with styles. Tables are only used within a <div>.
P R E F A C E vii
Chapter Organization
Each chapter begins with identifiable objectives and a brief overview. Numer-
ous coding examples as well as hands-on projects with guidance for the coding
appear throughout. Thought-provoking feedback questions give students time
to reflect on the current topic and to evaluate their understanding of the de-
tails. The end-of-chapter items include key terms, a chapter review, questions,
programming exercises, and two case studies. The case studies provide a
continuing-theme exercise that may be used throughout the course. The
in-chapter programs are included on the student Web site, allowing the student
to test and modify existing code. Of course, it is also important to develop a
complete application from scratch to really learn the programming techniques.
Chapter 1, “Visual Studio and the .NET Framework,” discusses the
features of the Visual Studio IDE and the .NET Framework. Applications
demonstrate how to display data from the AssemblyInfo.vb file using the
My object. MDI projects, toolbars, and status bars are reviewed.
Chapter 2, “Building Multitier Programs with Classes,” reviews
object-oriented terminology, creating classes, and instantiating objects.
Creating and throwing exceptions from the business services tier is
introduced. The ErrorProvider and TryParse are demonstrated to
improve the efficiency of validation in the presentation tier.
Chapter 3, “Windows Database Applications,” explains the
relationship of datasets, tables, rows, and constraints. Database
applications use SQL Server databases to display information in grids,
combo boxes, labels, and the database display controls.
6 Bradley−Millspaugh: Front Matter Preface © The McGraw−Hill
Advanced Programming Companies, 2010
Using Visual Basic 2008
viii P R E F A C E
P R E F A C E ix
Acknowledgments
We would like to express our appreciation to the many people who have con-
tributed to the successful completion of this text. Most especially, we thank the
students at Mt. San Antonio College who helped class-test the material and
who greatly influenced the manuscript.
Many people have worked very hard to design and produce this text.
We would like to thank our editors Liz Haefele, Scott Davidson, and Alaina
Grayson. Our thanks also to the many people who produced this text including
Marlena Pechan, and Betsy Blumenthal.
We greatly appreciate John Blyzka, Peter van der Goes, and Robert Price
for their thorough technical reviews, constructive criticism, and many valuable
suggestions. And most importantly, we are grateful to Dennis and Richard for
their support and understanding through the long days and busy phone lines.
8 Notes
Bradley−Millspaugh: Front Matter To the Student © The McGraw−Hill 9
Advanced Programming Companies, 2010
Using Visual Basic 2008
TO THE STUDENT
Welcome to the exciting new features of Visual Basic 2008. You have probably
already learned that the best way to learn how to program is to actually sit at
a computer and write code, change things, and test it again. Stepping through
existing code is also a great tool in learning new techniques. With that in mind,
we have included all of the code from the examples within the chapters on your
student text Web site. Please feel free to load the programs, change things, and
test it again.
But . . . if you really want to learn how it works, it is critical that you create
a blank project and try the techniques yourself. If you run into a problem, take
a look at the sample and compare properties and code.
There are several tools in this text to help you on your way.
• Each chapter begins with a list of topics and ends with a summary. Com-
bine these for a thumbnail review of the chapter. Understanding the ter-
minology is an important part of learning any new language, which is also
true with programming languages.
• A list of key terms is at the end of each chapter. Each of those terms is in
boldface within the chapter. There is also a glossary at the end of the text
where you can look up the definition of the terms.
• Test yourself with the Feedback questions as you work through each sec-
tion of a chapter. The review questions at the end of the chapter can test
your understanding of the topics.
• Tips are included to give suggestions in situations where you may run into
problems caused by the version of software installed/not installed or with
settings.
• Make sure to check out the appendixes, which hold a wealth of support
material.
J.C.B.
A.C.M.
xi
10 Notes
Bradley−Millspaugh: 1. Visual Studio and the Text © The McGraw−Hill 11
Advanced Programming .NET Framework Companies, 2010
Using Visual Basic 2008
Try
With StoresBindingSource
C H .EndEdit()
A P T E R
.AddNew()
1 End With
AddingBoolean = True
SetComboBoxBinding()
Stor_nameComboBox.Focus()
SetControlsReadOnly(False)
PreviousSelectedIndex = 0
End If
at the completion of this chapter, you will be able to . . .
1. Distinguish the features of the Visual Studio IDE and the .NET Framework.
2. Identify and understand the purpose of each of the files listed in the Solution Explorer.
5. Create an MDI project with a parent form, child forms, a toolbar, status bar, context menus,
and ToolTips.
6. Use the singleton design pattern to create a class that should be instantiated only once.
12 Bradley−Millspaugh: 1. Visual Studio and the Text © The McGraw−Hill
Advanced Programming .NET Framework Companies, 2010
Using Visual Basic 2008
C H A P T E R 1 3
System.IO Types for reading and writing data streams and files.
The classes in the library comply with published standards known as the
Common Language Specification (CLS). The CLS specifies how a lan-
guage that interacts with the CLR should behave. If you want a program to in-
teract with programs and components written in other languages, you should
make sure that it is CLS compliant. The rules for CLS compliance can be found
in the .NET Framework Developer’s Guide under the heading “Writing CLS-
Compliant Code.” Note that all VB programs that you write using the VS IDE
will be CLS compliant automatically.
Types
The .NET documentation uses the general term types to refer to the classes,
structures, enumerations, delegates, interfaces, and data types in the library, as
well as any that you define. You can think of a type as any element that you can
use in the As clause of a declaration:
treat the variables when you assign one variable to another. For example, if you
assign one integer variable to another, you have two memory locations with the
same value:
SecondValueInteger = FirstValueInteger
However, if you assign one reference type to another, you have two variables
that point to the same object in memory:
SecondForm = FirstForm ' Assign reference for first form to second form.
Any changes that you make to either variable are made to the one object in
memory to which both variables refer. In some previous versions of VB, refer-
ence types were called object variables. However, VB reference types include
more types than the more restrictive object variables.
Can you predict the debug output from the two groups of statements above?
Follow the logic and write down your answer; then look back here to check
your understanding.
FirstValueInteger = 5; SecondValueInteger = 10
FirstForm = New Caption for First Form; SecondForm = New Caption for First Form
All numeric data types are value types. Reference types include class types,
arrays (even if the individual elements are numeric), and strings. A value type
always holds a value; when you declare a new variable of a value type, the vari-
able is always initialized, either to a value that you supply or to the default value.
A reference type may or may not hold a value; you can use the IsNot Nothing
condition to determine whether the variable refers to an instance of an object.
C H A P T E R 1 5
Assemblies
An assembly is a basic unit of code that may be a single PE file or multiple
files. Each of your applications will be contained in a single assembly, which
is the smallest deployable piece of code. An assembly has an assembly man-
ifest that contains metadata about the version, a table describing all of the
files needed by the assembly, and an “assembly reference list” that specifies
all of the external files needed, such as DLLs created by someone else. An
assembly is similar to an .exe or a .dll file written in earlier versions of Visual
Basic—it contains all of the necessary information to run the application or
component.
Recall that the .NET Framework class library is not one big file but
rather a collection of files. The classes are stored in many files with the ex-
tension .dll and referred to as DLLs (for dynamic link libraries). Each of the
DLLs in the class library is one assembly. As your program begins execu-
tion, only the needed assemblies are loaded into memory. When you want to
use a type that is not already referenced, you must add a reference to the
DLL (assembly).
Attributes
Attributes are tags containing information about parts of a program such as
types or methods. The system defines many attributes of your assembly, such
as the name, version, culture, and security. The attributes are part of the meta-
data in a .NET assembly. The process of examining the metadata in an assem-
bly’s attributes is called reflection.
Later in this chapter, you will learn to retrieve and use the custom attri-
butes in a project’s assembly information, which is stored in the Assembly-
Info.vb file.
ASP.NET
Another big part of the .NET world is the improvement in Web development.
ASP.NET 3.5 is the newest version of Active Server Pages (ASP). It is a Web
development environment that can compile applications written in any .NET-
compatible language including Visual Basic. This means that the benefits of the
common language runtime and managed code are available for developing Web
applications. ASP.NET makes Web development easier by providing the same
debugging support for Web Forms and Web Services as for Windows applications.
You will begin working with ASP.NET in Chapter 7. Chapters 8 and 9
cover accessing databases from ASP.NET, which is a common technique for
displaying data on a Web site.
➤ Feedback 1.1
1. What is meant by the term .NET Framework?
2. What are the meaning and function of each of these terms?
a. CLR
b. CLS
c. MSIL
d. PE
3. What is the difference between a reference type and a value type? Why
is it important to know the difference?
Visual Studio
Although you could write your programs in any editor and then use the VB com-
piler to compile them, Visual Studio provides an environment to make your devel-
opment task easier. You should already be familiar with the various windows in the
environment as well as the basic debugging capabilities. For a review of the VS
IDE, as well as tips and shortcuts, see Appendix D. This section introduces you to
more details about the parts of a project and changes to the VS environment.
Note: This chapter introduces writing Windows applications. You also have
the option of writing Windows Presentation Foundation (WPF) applications.
Although WPF applications are introduced in Chapter 13, you might prefer to
begin there and write all of your programs using WPF.
Temporary Projects
You can create temporary projects for testing, without saving them. This can be
both good and bad: You don’t have to clutter your drive with small projects that
you create just to test something, but you may forget to save a project that you
wanted to keep.
When you create a new project, by default it is a temporary project, which
VS stores in a temporary folder on the hard drive. So even when you compile
and run the project, the compiler saves the files in the temporary folder. When
you exit VS or choose to begin another project, you are presented with the
option to save or discard the project (Figure 1.2).
If you want to always save new projects, you can select that option in the
Options dialog box. Choose Tools / Options / Projects and Solutions and select
Save new projects when created.
Bradley−Millspaugh: 1. Visual Studio and the Text © The McGraw−Hill 17
Advanced Programming .NET Framework Companies, 2010
Using Visual Basic 2008
C H A P T E R 1 7
Figure 1.2
bin\Debug folder
obj folder
Bradley−Millspaugh: 1. Visual Studio and the Text © The McGraw−Hill 19
Advanced Programming .NET Framework Companies, 2010
Using Visual Basic 2008
C H A P T E R 1 9
hidden files and folders. The My Project folder holds several files for project
configuration, including AssemblyInfo.vb. You will learn to view and set con-
figuration options in the Project Designer, which is discussed in the “The
Project Designer” section later in this chapter.
In Figure 1.4, you can see the expanded References collection, the bin and
obj folders, and the form files for Form1.vb. You can expand each of the nodes
to see more details. Note that the solution name does not display by default. To
show the solution name, as in Figure 1.4, select Tools / Options / Projects and
Solutions and check Always show solution. You will want to always show solu-
tions so that you can edit solution names.
References
In the References folder, you can see a list of System libraries (DLLs), such as
System, System.Deployment, System.Drawing, and System.Windows.Forms.
These are the references included by default for a new Windows application.
You can add a reference by right-clicking on the References folder and select-
ing Add Reference from the context menu. You also can add references in the
Project Designer, which is discussed a little later. You may need to add a refer-
ence if you want to refer to objects in another assembly or components written
in a different language.
The executable
Debugging information
20 Bradley−Millspaugh: 1. Visual Studio and the Text © The McGraw−Hill
Advanced Programming .NET Framework Companies, 2010
Using Visual Basic 2008
The project’s .exe file is the executable, which is used to run the program; the
.pdb file holds debugging information. If you are distributing your application,
you only need to distribute the .exe file, not the .pdb file. The ProjectName.
vshost.exe file is a small application that runs the project in the environment.
Project Resources
The Resources folder holds resources that you add to your project. Figure 1.6
shows a graphic file stored in the Resources folder; you can also add sound
files and text strings to the resources.
Figure 1.6
Visual Studio provides several ways to add resources to the folder and to
access those resources. You can add resources in the Project Designer, dis-
cussed later in this chapter. You also can add resources from the Properties
window, such as when you set the Image property of a PictureBox control. At
design time, you can assign properties of controls to resources that are in the
Resources folder, and you can retrieve resources at run time using the My.Re-
sources object, which also is discussed later in this chapter.
Each form in your project also has a resource file, which has a .resx exten-
sion. For example, Form1.vb has a Form1.resx file, which you can see in the
Solution Explorer when you click on the Show All Files button and expand the
form’s node.
The .resx file is mostly text in XML format, which you can open and view
in the IDE. The .resx file holds pointers to the files in your Resources folder
and supplies the resources to the form at compile time. Any graphic elements
that you add to the form, such as a PictureBox’s Image property or a form’s
Icon property, also are stored in the .resx file in text that represents the binary
graphic file.
If you rename your form file in the Solution Explorer, the .resx file is auto-
matically renamed to match. At times you may find extra .resx files in the
project’s folder; you can safely delete any extra .resx files if their names do not
match any forms in the project.
Image Files in Visual Studio 2008 Microsoft is including many graphic files
with Visual Studio 2008. The graphics are those used in Windows so that you
can make your applications use the standard images. The default location for
Bradley−Millspaugh: 1. Visual Studio and the Text © The McGraw−Hill 21
Advanced Programming .NET Framework Companies, 2010
Using Visual Basic 2008
C H A P T E R 1 11
Partial Classes
Partial classes, also called partial types, is a feature that was added in the
2005 version of Visual Studio. In its simplest form, partial classes allow you to
split a class into two or more separate files.
Programmer-written VB code
Designer-generated VB code
Resource file for the form
The file that holds the designer-generated code includes the class inheri-
tance information:
The partial class instantiates the form and the visual components for the
form as well as stores property settings.
The form’s class file that holds the programmer-written code begins with
this line:
The compiler uses the statements in both files to create the compiled class.
Note that you can create multiple partial class files and one single file without
the “Partial” designation.
22 Bradley−Millspaugh: 1. Visual Studio and the Text © The McGraw−Hill
Advanced Programming .NET Framework Companies, 2010
Using Visual Basic 2008
Display the Project Designer by double-clicking on the My Project folder in the Solution Explorer.
Assembly
information
The Application Tab The Application tab is the default tab that appears on top
when you open the Project Designer. On the Application tab, you can set the ap-
plication type, the startup form, the icon, and the splash screen. You also can
display and set the application’s assembly information from this dialog. Later
in this chapter, we will use many of these options.
The Compile Tab On the Compile tab, you can set the path for the compiler
output. You also can alter the settings for Option Explicit and Option Strict
and specify which errors should be flagged by the compiler and which should
be ignored.
The References Tab The References tab displays the names and paths for the
project references. You can add and remove references to Windows or Web
library components, as well as external components, in this dialog.
The Resources Tab The Resources tab allows you to easily add and remove the
graphic files that you use for picture boxes and toolbars, any sound files, and
text strings in various languages to use for localization.
Bradley−Millspaugh: 1. Visual Studio and the Text © The McGraw−Hill 23
Advanced Programming .NET Framework Companies, 2010
Using Visual Basic 2008
C H A P T E R 1 13
The Signing, Security, and Publish Tabs The settings on the Signing, Security,
and Publish tabs are used for ClickOnce deployment. Using ClickOnce deploy-
ment, you can set up applications to be deployed and updated on multiple sites
via the Web. This technique is primarily used by large organizations to facili-
tate deploying applications to many users.
The VB My Objects
The Visual Basic My object provides several objects and properties. My gives
you easy access to information about your application and its resources, the
computer on which the application is executing, and the current user.
It is easy to discover the available objects using IntelliSense (Figure 1.9):
Application, Computer, Forms, Resources, Settings, User, and Web Services.
Figure 1.9
You can retrieve information about the user’s computer, operating system,
and amount of memory with My.Computer.Info (Figure 1.10).
If you want to know the name of the user, you can use
UserNameString = My.User.Name
In the following section, you will use My.Application to retrieve the assem-
bly information about an application.
Figure 1.10
Use My.Computer.Info to
retrieve information about
the user’s computer.
Figure 1.11
C H A P T E R 1 15
Figure 1.12
Type appropriate entries for your applications. Figure 1.12 shows the as-
sembly information for the chapter hands-on example program.
Another way to modify a project’s assembly information is to edit the
AssemblyInfo.vb file directly. You can see the file in the Solution Explorer
beneath the My Project folder when Show All Files is selected (Figure 1.13).
Double-click the filename to display the file in the editor.
Figure 1.13
You can modify the assembly information by editing the AssemblyInfo.vb file.
26 Bradley−Millspaugh: 1. Visual Studio and the Text © The McGraw−Hill
Advanced Programming .NET Framework Companies, 2010
Using Visual Basic 2008
TitleLabel.Text = My.Application.Info.Title
C H A P T E R 1 17
Write the code to assign values to the labels in the Form_Load event
procedure. The code uses the My.Application.Info object to retrieve the
attributes.
With My.Application.Info
NameLabel.Text = .AssemblyName
TitleLabel.Text = .Title
DescriptionLabel.Text = .Description
CompanyLabel.Text = .CompanyName
ProductLabel.Text = .ProductName
VersionLabel.Text = "Version: " & .Version.ToString
CopyrightLabel.Text = .Copyright
End With
End Sub
Figure 1.15
➤ Feedback 1.2
Write the statements necessary to retrieve and display the copyright attribute
in CopyrightLabel.
The MenuStrip,
ContextMenuStrip, ToolStrip,
and StatusStrip components
are grouped together in the
Menus & Toolbars section of
the toolbox.
C H A P T E R 1 19
You can use the MenuStrip’s smart tag (Figure 1.20) to set some properties of
the menu bar. Select Edit Items to open the Items Collection Editor (Figure 1.21),
where you can set properties of the menu items, and add, remove, and rearrange
the items.
When you use the visual menu designer to create menus and menu items,
each item is automatically given a meaningful name. But if you add a menu
item in the Items Collection Editor, you must name the item yourself.
Figure 1.20
TIP
The keyboard shortcut for opening
a smart tag when its arrow appears
is Alt + Shift + F10. ■
Figure 1.21
In the Items Collection Editor, you can add and remove menu items, reorder items, and set properties of the items.
You can edit any of the items by selecting it in the Members list. Figure 1.22
shows the FileToolStripMenuItem selected. Notice that the top right now indicates
the selected item and that one of the properties of the FileToolStripMenuItem is a
DropDownItems collection. If you select that collection, the Items Collection
Figure 1.22
Edit the properties of the individual menu items in the Items Collection Editor. Notice that the FileToolStripMenuItem has a
DropDownItems property, which is a collection of the menu items that appear below the File menu.
FileToolStripMenuItem is selected
C H A P T E R 1 21
Editor displays the items beneath the File menu. Also notice in Figure 1.22 that
the right side of the Items Collection Editor is similar to the Properties window in
the IDE. You can click on the buttons to display the properties in alphabetic order
or categorized view.
Figure 1.23
The ContextMenuStrip component appears in the component tray. When it is selected, the visual menu designer appears to
allow you to enter menu items.
A context menu does not include a top-level menu name; instead each of the
items belongs to the Items collection of the ContextMenuStrip. Notice that the
smart tag arrow appears on the component in the component tray, rather than on
the menu in the designer. You can select Edit Items from the smart tag or select
the Items property in the Properties window to edit the individual menu items.
The form and each of the controls that you add to the form has a Context-
MenuStrip property. You assign the context menu to the form or control by se-
lecting its name in the Properties window. Note that you can add multiple
context menus to the component tray and assign each to a different control.
If you assign a context menu to a form, it becomes the default context menu
for the form and most controls on the form. However, controls that allow text
entry, such as text boxes and combo boxes, have a default context menu that
contains the editing items Cut, Copy, and Paste. If you assign your own context
menu to a text control, you will lose the items on the default context menu.
You can easily assign a single event handler to both a menu item and a
context menu item. Add the second item to the Handles clause of the event
handler. In the following example, the event handler is executed for the Click
32 Bradley−Millspaugh: 1. Visual Studio and the Text © The McGraw−Hill
Advanced Programming .NET Framework Companies, 2010
Using Visual Basic 2008
event of both the menu item and context menu item. Note that the menu
designer named the context menu item with the same name as the menu item,
with the addition of the numeral “1”.
Me.Close()
End Sub
Figure 1.24
The ToolStrip component appears in the component tray. You can drop down the list for the types of buttons and controls that
you can add to the ToolStrip.
After you add the buttons to the ToolStrip container, you can set the prop-
erties of each button in the Properties window or in the Items Collection Editor, TIP
which you display from the smart tag. You will need to give the toolbar buttons Set the ToolTipText property of each
meaningful names; the visual designer assigns names like ToolStripButton1. toolbar button to aid the user, in
Your buttons can hold an image, text, or both. Generally you will want to case the meaning of each graphic is
place an image on the button and set the ToolTip text to indicate the purpose of not perfectly clear. ■
Bradley−Millspaugh: 1. Visual Studio and the Text © The McGraw−Hill 33
Advanced Programming .NET Framework Companies, 2010
Using Visual Basic 2008
C H A P T E R 1 23
Figure 1.25
Set the Name, Image, and ToolTipText properties for each ToolStripButton.
ToolTip
Name
DateToolStripStatusLabel.Text = Today.ToShortDateString
TimeToolStripStatusLabel.Text = Now.ToLongTimeString
End Sub
34 Bradley−Millspaugh: 1. Visual Studio and the Text © The McGraw−Hill
Advanced Programming .NET Framework Companies, 2010
Using Visual Basic 2008
Figure 1.26
DateToolStripStatusLabel.Text = Today.ToShortDateString
TimeToolStripStatusLabel.Text = Now.ToLongTimeString
End Sub
Bradley−Millspaugh: 1. Visual Studio and the Text © The McGraw−Hill 35
Advanced Programming .NET Framework Companies, 2010
Using Visual Basic 2008
C H A P T E R 1 25
➤ Feedback 1.3
What steps are necessary to display the current time in a StatusStrip label
called CurrentTimeStatusStripLabel?
MDI Applications
In this section, you will create a multiple document application with parent
and child forms, a menu bar, context menus, a toolbar, and a status bar.
With MDI, a parent and child relationship exists between the main form
and the child forms. One of the rules for MDI is that if a parent form closes, all
of its children leave with it—a pretty good rule. Another rule is that children
cannot wander out of the parent’s area; the child form always appears inside
the parent’s area.
VB allows you to have forms that act independently from each other. You
may have a parent form and several child forms and some forms that operate
independently. For example, a splash form likely should remain SDI.
One feature of MDI is that you can have several child windows open at the
same time. The menu bar generally contains a Window menu that allows you to
display a list of open windows and move from one active window to another.
Random documents with unrelated
content Scribd suggests to you:
CHAPTER XIX
A GALLOPING TO AND FRO
ATHURA slept little during the remainder of the night. She insisted
on watching a part of the time, while Gustasp slept stretched out on
the floor and the maids tried to rest. She watched while the stars
paled and the gray light of the dawn grew into rosy sunrise and
cloudless day. Her eyes eagerly scanned the horizon towards
Nicæa. As soon as the light was sufficient, she saw moving bodies of
horsemen concentrating in the plain near the base of the hill on
which the castle stood. She had often seen large bodies of troops,
and she estimated that not less than thirty thousand were there.
Officers were busily riding hither and thither placing them in line with
their faces towards Nicæa.
When Gustasp awoke and observed the movements of the troopers,
he gave it as his opinion that an attack was expected. Nor was he
mistaken. For about mid-forenoon they observed two bodies of
cavalry approaching from the direction of Nicæa, one in advance
moving rapidly and the other more deliberately. The advance body
was evidently a scouting party sent out by Prexaspes, and it soon
joined his array. The pursuers came on in wide, extended order, their
masses glittering with armor and spear-points. At their head rode two
men, conspicuous on white steeds.
“Look, Gustasp!” exclaimed Athura, while the pursuers were yet far
away. “Is it not the Prince—the one at the right? Is that not Gobryas
at his left?”
Gustasp shaded his eyes and looked closely at the distant figures.
He smiled and shook his head.
“My eyes are counted good, gracious lady, but I cannot see any
difference in those men,” he answered. “If I had eyes as young as
yours, I might distinguish them. But I know those are the Persians of
the Imperial Guard. The Prince must be with them. They are not half
as numerous as the false King’s men, but they are veterans and the
best soldiers in the world. It will be a short battle.”
The Persians came on until they were within a thousand paces of
their antagonists, when they halted. The two leaders rode forward to
a slight eminence two hundred paces in advance, from which they
attentively surveyed the field. It was well suited for battle between
bodies of cavalry. While somewhat rolling and uneven, there were no
ditches or swamps. The Medean line was more extended than the
Persian and no less massive and deep. The Persian leaders soon
returned to their lines and the watchers on the hills perceived a
movement of the rear ranks to the left, where presently a body of
troops was massed three times as great in depth as the general line.
“The Prince has made a hammer of his left,” said Gustasp. “Now
look at his right! It bends back so that the Medes may not overlap
and attack the Persian rear!”
It was even so. For when the Persians moved forward again there
was a perceptible bending back of their right wing until it moved
forward en echelon to the remainder of the line.
Then came two men from the Persians who rode rapidly up to the
Medes and demanded a parley. Prexaspes and the King met them
and received a message from the Prince of Iran demanding the
surrender of the Princess Athura and of the false King, and
promising pardon to all the other Medes save Prexaspes. These
demands were refused. The heralds rode back to the Prince and
reported, who then ordered his army to advance.
The Persians came on at a smart trot until within five hundred yards.
Then the front ranks leveled their spears, bent their bodies forward,
and pressed their horses into a gallop. Prexaspes ordered his troops
forward to meet the onset. The earth shook with the thunder of
hoofs. A deep-toned roar went up from the Persians, their battle
shout which had terrified many a nation. The Medes answered with a
medley of yells. The lines came together with a terrific shock. Men
were unhorsed. Horses reared, plunged, and went down. Screams of
agony mingled with battle-shouts. The lines wavered and stood still,
it seemed, for the space of five minutes. Then was seen the power of
discipline. The Medes, while brave, were not inured to battle. After
the first shock, they became confused. They were overthrown,
ridden down, and pushed back. Struggling fruitlessly against the
terrible spears of their enemies, they receded. The Persians raised
shouts of victory and pressed their advantage. The Prince of Iran,
leading the center, rode over Prexaspes, broke through the Medean
lines, and made directly for the King. The latter turned his horse and
fled towards his castle, with the Prince and Gobryas close at his
heels. So close was the pursuit that Gaumata and his men had no
time to close the brazen gates of the castle, which were opened to
receive them, before the Prince and Gobryas with a company of
Persians pressed through and attacked the garrison fiercely.
Demoralized by the fall of Prexaspes and the flight of Gaumata, the
Medean army scattered and fled from the field.
The Prince and Gobryas, swords in hand, pressed through the
confused rabble after Gaumata. They saw him leap from his horse
and enter the castle. Dismounting they pursued him into the
chamber below that where the Princess Athura had her retreat. Here
the false King turned at bay, unable to escape. The Prince himself
attacked Gaumata, though Gobryas begged the privilege of slaying
him. The struggle was short. The Prince was an athlete and
swordsman; his opponent was neither. Gaumata’s weapon was
whirled from his hand at the first blow, and the Prince’s blade passed
through his heart, cutting short his cry for mercy.
Athura, trembling with excitement, had seen the battle and the flight
and pursuit of Gaumata, and, from behind Gustasp’s broad
shoulders on the stairs, had watched the short, sharp combat
between the Prince and the usurper. The Prince, flushed with victory
as he stood above the writhing form of Gaumata, heard her exclaim,
“Ahura-Mazda be praised!” He turned and their eyes met. He sprang
towards Gustasp with dripping sword, thinking the giant guard an
enemy in charge of the royal captive. But Athura pressed forward in
front of Gustasp, exclaiming, “He is a friend!”
The Prince dropped his sword and extended his arms, with the light
of great love in his eyes. Athura threw her arms about his mail-
covered shoulders. Gustasp and Gobryas drove back the crowd of
Persian troopers who were pressing in to aid their Prince.
But a chief commander must make an end of greetings, no matter
how entrancing. The Prince and Athura passed out into the
courtyard, now filled with shouting Persians, some of whom were
pursuing the luckless garrison and cutting them down. When the
Persians saw the radiant Athura standing by the side of their Prince,
their shouts rent the heavens. For every man who had taken part in
the battle knew that their leader was seeking to rescue his promised
wife, the daughter of the great Cyrus.
Prexaspes was among the prisoners. His horse had been killed and
had fallen upon him. The Persian cavalry had passed over him. But
save for a broken arm, he was not seriously injured. He was brought
before the Prince. His countenance showed signs of suffering, but
the usual calm, cynical smile rested upon it and he exhibited no fear.
The Prince looked upon him sternly.
“At last, Prexaspes,” he said, “you have come to a day of judgment!
What have you to say?”
“Nothing, great Prince,” he answered. “Fate has turned against me. I
am in your hands, a prisoner of war.”
“But how could you, a noble of Medea, conspire with that carrion,
Gaumata? And you even obeyed him as King!”
“I did not conspire. I was faithful to Cambyses till he died—even
though he did slay my son, as you know, in cruel jest. I did not
conspire against him. What could I do after his death? By the
command of Cambyses, I had slain Prince Bardya. For that crime I
knew that I would be slain by you. So I came and offered my sword
to the false King. He obeyed me, not I him!”
The Prince contemplated his prisoner gloomily. No man ever more
admired courage than he. Prexaspes smiled in the face of death.
What punishment should be meted out to such a man?
“For taking Bardya’s life, you have merited death,” said the Prince,
finally. “But you are a brave man. You shall die as such. Tell me,
Prexaspes, how did Bardya die?”
“I expect to die,” answered Prexaspes, and the pain and despair of
his soul snatched away the smile from his face, leaving his
handsome features haggard and drawn. “Remorse has been with
me, since by this hand the stout young Prince departed! I will tell
you. Cambyses was jealous of Bardya. His advisers, the Magian
priests, who by their wonder works had made much impression on
the King’s mind, also hated Bardya because he clung to the ancient
religion of Iran and was an enemy to their religion. They knew that
with Bardya as King they would never gain power in the state. They
hinted to the King that Bardya contemplated rebellion. They artfully
brought stories of the young man’s popularity. They advised his
death. It was then that the King laid his command upon me to slay
his brother. The Magian priests sent a body of their armed followers
to lie in wait on the road to Rhages that night when the feast in honor
of the Prince’s departure was held; and I rode with Bardya that night
until, as prearranged, they attacked us. Then, in the mêlée, I struck
the Prince with my sword and he died. Was not the Great King’s
word law? I executed his word, without malice towards the Prince.
But I am weary of life! My wife is dead. Cambyses slew my son. I
have run the full course of power and wealth. I am your prisoner,
ready to die. But know this, great Prince, I have never advised
Cambyses against your interests!”
The Prince listened attentively and believed that Prexaspes spoke
truthfully. He turned to Athura, who had listened to the recital, and
asked, “What do you advise?”
Athura shook her head sadly.
“I cannot advise,” she said. “Last night when the drunken priests and
the false King attempted to break into the castle and do me harm,
this man interfered and compelled them to cease.”
“For that, Prexaspes, I would pardon you, had I the power,” said the
Prince, turning to the prisoner. “I could order you slain now, but I
cannot slay you. Prexaspes, you have deserved my gratitude. I grant
you life for the present. I am not the King. My father is King of Iran.
There is no King of Kings; until the nobles of Bactra, Persia, and
Medea shall select one of the Achæmenian line. You shall go to
Hamadan to be judged.”
“Rather would I be slain by you now,” responded Prexaspes,
earnestly. “Let me die a soldier’s death, not the death of a dog
condemned for murder!”
The Prince was troubled. He hesitated. Sympathy for a brave man
moved him.
“I promise you this, Prexaspes,” he said after a moment of
consideration. “If you will testify before the council of nobles and to
the people, that this Gaumata was a false traitor and not Bardya and
that Bardya was slain by your hand, I promise that you may choose
the manner of your death. The King and the nobles will heed my
promise. They will not deny me. If you make this confession and
implicate the Magian priest, they will pursue you with bitter
vengeance. It is said that their death penalties are tortures such as
even fiends would not inflict. We could not save you from them. It is
the ancient law that one who lifts his hand against one of the
Achæmenian race must die. Is it not so? And this law, not even the
King may set aside.”
“It is so!” answered Prexaspes. “I will testify before the people and
the council, in order that your reign as King of Kings may not be
disturbed by other false Bardyas. I advise that you carry this
Gaumata’s head to Hamadan and exhibit it in the market that all may
see. I myself will ascend the criers’ tower and confess the death of
Bardya to the people. So be it. I will choose my own death.”
“Meanwhile,” said the Prince, “Gobryas shall be your keeper. He will
treat you as a brave soldier should treat a brave soldier unlucky
enough to be a captive. We shall rest here this night. On the morrow
we march to Hamadan.”
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com