0% found this document useful (0 votes)
81 views

Instant Download Programming in Visual C 2008 3rd Edition Julia Case Bradley PDF All Chapters

Programming

Uploaded by

shikhoeryurt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

Instant Download Programming in Visual C 2008 3rd Edition Julia Case Bradley PDF All Chapters

Programming

Uploaded by

shikhoeryurt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

Download Full ebookname - Read Now at ebookname.

com

Programming in Visual C 2008 3rd Edition Julia


Case Bradley

https://ebookname.com/product/programming-in-
visual-c-2008-3rd-edition-julia-case-bradley-2/

OR CLICK BUTTON

DOWLOAD EBOOK

Discover More Ebook - Explore Now at ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Programming in Visual C 2008 3rd Edition Julia Case


Bradley

https://ebookname.com/product/programming-in-visual-c-2008-3rd-
edition-julia-case-bradley/

ebookname.com

Programming in Visual Basic 2008 7th Edition Julia Case


Bradley

https://ebookname.com/product/programming-in-visual-basic-2008-7th-
edition-julia-case-bradley/

ebookname.com

Beginning Visual C 2012 programming 1st Edition Karli


Watson

https://ebookname.com/product/beginning-visual-c-2012-programming-1st-
edition-karli-watson/

ebookname.com

Job Aids and Performance Support Moving From Knowledge in


the Classroom to Knowledge Everywhere Essential Knowledge
Resource 2nd Edition Allison Rossett
https://ebookname.com/product/job-aids-and-performance-support-moving-
from-knowledge-in-the-classroom-to-knowledge-everywhere-essential-
knowledge-resource-2nd-edition-allison-rossett/
ebookname.com
The Routledge Companion to Sociolinguistics Carmen Llamas

https://ebookname.com/product/the-routledge-companion-to-
sociolinguistics-carmen-llamas/

ebookname.com

Power of Fate Mystic Harbor Book 1 1st Edition Suki


Williams

https://ebookname.com/product/power-of-fate-mystic-harbor-book-1-1st-
edition-suki-williams/

ebookname.com

Handbook of Firearms and Ballistics Brian J. Heard

https://ebookname.com/product/handbook-of-firearms-and-ballistics-
brian-j-heard/

ebookname.com

Personal Branding in the Knowledge Economy The


Interrelationship between Corporate and Employee Brands
1st Edition Wioleta Kucharska
https://ebookname.com/product/personal-branding-in-the-knowledge-
economy-the-interrelationship-between-corporate-and-employee-
brands-1st-edition-wioleta-kucharska/
ebookname.com

Residual Stress Effects on Fatigue and Fracture Testing


and Incorporation of Results Into Design Michael R.
Mitchell
https://ebookname.com/product/residual-stress-effects-on-fatigue-and-
fracture-testing-and-incorporation-of-results-into-design-michael-r-
mitchell/
ebookname.com
Investigations in Environmental Geology 3rd Edition Duncan
D. Foley

https://ebookname.com/product/investigations-in-environmental-
geology-3rd-edition-duncan-d-foley/

ebookname.com
Computer and Information Technology

Programming in Visual C#
2008

Bradley−Millspaugh

McGraw-Hill
=>?
McGraw−Hill Primis

ISBN−10: 0−39−017402−5
ISBN−13: 978−0−39−017402−4

Text:

Programming in Visual C# 2008


Bradley−Millspaugh
This book was printed on recycled paper.

Computer and Information Technology

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.

This McGraw−Hill Primis text may include materials submitted to


McGraw−Hill for publication by the instructor of this course. The
instructor is solely responsible for the editorial content of such
materials.

111 COMPGEN ISBN−10: 0−39−017402−5 ISBN−13: 978−0−39−017402−4


Computer
and
Information
Technology

Contents

Bradley−Millspaugh • Programming in Visual C# 2008

Front Matter 1
Preface 1
To the Student 7

1. Introduction to Programming and Visual C# 2008 9


Text 9

2. User Interface Design 75


Text 75

3. Variables, Constants, and Calculations 115


Text 115

4. Decisions and Conditions 165


Text 165

5. Menus, Common Dialog Boxes, and Methods 225


Text 225

6. Multiform Projects 267


Text 267

7. Lists, Loops, and Printing 301


Text 301

8. Arrays 339
Text 339

iii
9. Web Applications 377
Text 377

10. Database Applications 419


Text 419

11. Data Files 459


Text 459

12. OOP: Creating Object−Oriented Programs 489


Text 489

13. Graphics, Animation, Sound, and Drag−and−Drop 543


Text 543

14. Additional Topics in C# 579


Text 579

Back Matter 621


Appendix A: Answers to Feedback Questions 621
Appendix B: Methods for Working with Dates, Mathematics, and
String Operations 635
Appendix C: Tips and Shortcuts for Mastering the Environment 643
Appendix D: Security 661
Glossary 665
Index 676

iv
Bradley−Millspaugh: Front Matter Preface © The McGraw−Hill 1
Programming in Visual C# Companies, 2010
2008

PREFACE

Visual C# (C Sharp) is a relatively new language introduced by Microsoft along


with Visual Studio. Its goal was to provide the ease of working with Visual
Basic with the flexibility and power of the Java and C++ languages. The syntax
of C# is similar to Java and C++ but the ease of creating a graphical user inter-
face and an event-driven application rivals Visual Basic.
C# is fully object-oriented, compatible with many other languages using
the .NET Framework. This book incorporates the object-oriented concepts
throughout, as well as the syntax and terminology of the language.
C# is designed to allow the programmer to develop applications that run
under Windows and/or in a Web browser without the complexity generally as-
sociated with programming. With very little effort, the programmer can design
a screen that holds standard elements such as buttons, check boxes, radio but-
tons, text boxes, and list boxes. Each of these objects operates as expected,
producing a “standard” Windows or Web user interface.

About This Text


This textbook is intended for use in an introductory programming course, which
assumes no prior knowledge of computer programming. The later chapters are
also appropriate for professional programmers who are learning a new language
to upgrade their skills.
This text assumes that the student is familiar with the Windows operating
environment and can use an Internet browser application.

Approach
This text incorporates the basic concepts of programming, problem solving,
and programming logic, as well as the design techniques of an object-oriented
event-driven language.
Chapter topics are presented in a sequence that allows the programmer to
learn how to deal with a visual interface while acquiring important program-
ming skills such as creating projects with objects, decisions, loops, and data
management.
A high priority is given to writing applications that are easy for the user to
understand and use. Students are presented with interface design guidelines
throughout the text.
This text follows essentially the same sequence as the Bradley/Millspaugh
Visual Basic text. Object-oriented programming (OOP) is introduced in Chap-
ter 1 and is used consistently in every chapter of the book.
The code for all in-chapter projects is available to instructors.
v
2 Bradley−Millspaugh: Front Matter Preface © The McGraw−Hill
Programming in Visual C# Companies, 2010
2008

TEXT FEATURES
Object-Oriented Concepts Interface Design Guidelines
are presented throughout the text to offer are presented to offer students a better under-
students an introduction to object-oriented standing of meeting user needs and employing
design before learning to create their own industry standards.
classes.
Good Programming Habits
try
1. Always test the tab order on your forms. Fix it if necessary by changing
{
the TabIndex properties of the controls.
//C Convert
H A input
P T values
E R to numeric and 2. Provide visual separation for input fields and output fields and always
quantityInteger = int.Parse(quantityTex make it clear to the user which are which.
try
{
1priceDecimal = decimal.Parse(priceT
// Calculate values.
extendedPriceDecimal = quantityInte
3. Make sure that your forms can be navigated and entered from the
keyboard. Always set a default button (AcceptButton property) for
every form.
4. To make a label maintain its size regardless of the value of the Text
property, set AutoSize to false.
5. To make the text in a text box right justified or centered, set the
TextAlign property.

Introduction to
discountDecimal = Decimal.Round(
(extendedPriceDecimal * DISCOUNT
6. You can use the Checked property of a check box to set other properties
that must be true or false.
amountDueDecimal = extendedPriceDec
Programming and
totalAmountDecimal += amountDueDeci
numberTransactionsInteger++;
Visual C# 2008
// Format and display answers.
extendedPriceTextBox.Text = extende Tips
at the completion of this chapter, you will be able to . . .

1. Describe the process of visual program design and development. in the margins help students avoid potential
2. Explain the term object-oriented programming. trouble spots in their programs and encourage
3. Explain the concepts of classes, objects, properties, methods, and
events. them to develop good programming habits.
4. List and describe the three steps for writing a C# program.

5. Describe the various files that make up a C# project.

6. Identify the elements in the Visual Studio environment.


TIP
7. Define design time, run time, and debug time. Use two ampersands when you
8. Write, run, save, print, and modify your first C# program.
want to make an ampersand appear
9. Identify syntax errors, run-time errors, and logic errors.
in the Text property: &Health &&
10. Look up C# topics in Help.
Welfare for “Health & Welfare”. ■

Feedback Questions Hands-On Programming


give the students time to reflect on the Examples
current topic and to evaluate their
understanding of the details. guide students through the process of planning,
writing, and executing C# programs.
➤ Feedback 2.1
Create a picture box control that displays an enlarged icon and appears in a 3D
box. Make up a name that conforms to this textbook’s naming conventions.
Your Hands-On Programming Example
Property Setting In this project, Look Sharp Fitness Center needs to expand the clothing sale
project done previously in this chapter. In addition to calculating individual
Name
sales and discounts, management wants to know the total amount of sales and
BorderStyle the number of transactions.
Add exception handling to the program so that missing or nonnumeric data
SizeMode
will not cause a run-time error.
Visible Help the user by adding ToolTips wherever you think they will be useful.
Bradley−Millspaugh: Front Matter Preface © The McGraw−Hill 3
Programming in Visual C# Companies, 2010
2008

Programming Exercises Case Studies


test students’ understanding of the pro- provide continuing-theme exercises that may
gramming skills covered in that chapter. be used throughout the course, providing many
opportunities to expand on previous projects.
Programming Exercises
3.1 In retail sales, management needs to know the average inventory figure
and the turnover of merchandise. Create a project that allows the user to Case Studies
enter the beginning inventory, the ending inventory, and the cost of goods
sold.
Custom Supplies Mail Order
Form: Include labeled text boxes for the beginning inventory, the ending
inventory, and the cost of goods sold. After calculating the answers, dis- The company has instituted a bonus program to give of the store’s total sales. The amount of sales needs to
play the average inventory and the turnover formatted in text boxes. its employees an incentive to sell more. For every dol- be entered only for the first employee. (Hint: Don’t
lar the store makes in a four-week period, the employ- clear it.)
ees receive 2 percent of sales. The amount of bonus The Calculate button will determine the bonus
each employee receives is based on the percentage of earned by this employee, and the Clear button will
hours he or she worked during the bonus period (a to- clear only the name, hours-worked, and bonus amount
at the completion of this chapter, you will be able to . . . tal of 160 hours). fields. A Print button allows the user to print the form.
h ll ll h h ll b d d l h
1. Use database terminology correctly.

2. Create Windows and Web projects that display database data.

3. Display data in a DataGridView control.


Learning Objectives
4. Bind data to text boxes and labels.
tell students what will be covered in the chapter
5. Allow the user to select from a combo box or list box and display the
corresponding record in data-bound controls. and what they will be able to do after completing
6. Query an object using LINQ. the chapter.

Online Learning Center


Visit the Visual C# 2008 Web site at www.mhhe.com/C#2008/
for instructor and student resoures.
4 Bradley−Millspaugh: Front Matter Preface © The McGraw−Hill
Programming in Visual C# Companies, 2010
2008

viii P R E F A C E

Changes in This Edition


This revision of the text is based on the Professional Edition of Visual Studio
(VS) 2008. The 2008 version of VS includes Language-Integrated Queries
(LINQ) for a more consistent means of querying a variety of data sources. The
Windows Presentation Foundation (WPF) brings new dimensions to interface
design. AJAX also has been added to provide faster postbacks for Web pages.
Microsoft has made many enhancements to the integrated development
environment (IDE). The Editor now has a much richer IntelliSense. New tool
windows for creating, managing, and applying styles in Web applications are
now included in Chapter 9.
A new PrintForm component makes printing a form extremely easy and conve-
nient for a classroom environment. The PrintForm component is part of a Microsoft
download called the Visual Basic Power Packs, which can be added to the IDE for
use with a C# program. PrintForm is covered in Chapter 2 for output to either the
printer or a Print Preview window. Standard printing is still covered in Chapter 7.
LINQ is covered in Chapter 10 (“Database Applications”) and again in the
XML section of Chapter 14.
Chapter 11 (“Data Files”) includes a simplified method for writing small
amounts of data without performing an open operation.
Drag-and-drop for images is now covered in the graphics chapter (Chapter
13). Students learn the development techniques for this familiar operation.
Chapter 14 includes XML data files and an introduction to programming
with WPF.
The text narrative, step-by-step exercises, screen captures, and appen-
dixes have all been updated to Visual Studio 2008. The screen captures are all
based on Windows Vista.

Features of This Text


Each chapter begins with identifiable objectives and a brief overview. Numerous
coding examples as well as hands-on projects with guidance for the planning and
coding appear throughout. Thought-provoking feedback questions give students
time to reflect on the current topic and to evaluate their understanding of the
details. The end-of-chapter items include a chapter summary, review questions,
programming exercises, and four case studies. The case studies provide a
continuing-theme exercise that may be used throughout the course.
Chapter 1, “Introduction to Programming and Visual C# 2008,”
introduces Microsoft’s Visual Studio integrated development environment
(IDE). The single environment is used for multiple languages. A step-by-
step program gets students into programming very quickly (quicker than
most books). The chapter introduces the OOP concepts of objects,
properties, methods, and events. The elements of debugging and using
the Help system also are introduced.
Chapter 2, “User Interface Design,” demonstrates techniques for good
program design, including making the interface easy for users as well as guide-
lines for designing maintainable programs. Several controls are introduced,
including text boxes, masked text boxes, rich text boxes, group boxes, check
boxes, radio buttons, and picture boxes. A new section covers the controls in
the Power Pack including PrintForm and the Shape and Line controls.
Bradley−Millspaugh: Front Matter Preface © The McGraw−Hill 5
Programming in Visual C# Companies, 2010
2008

P R E F A C E ix

Chapter 3, “Variables, Constants, and Calculations,” presents


the concepts of using data and declaring the data type. Students learn
to follow standards to indicate the data type of variables and constants
and to use the proper scope.
Error handling uses the try/catch/finally structure, which is
introduced in this chapter along with calculations. The student learns to
display error messages using the MessageBox class and also learns about
the OOP concept of overloaded constructors.
Chapter 4, “Decisions and Conditions,” introduces taking alternate
actions based on expressions formed with the relational and logical
operators. This chapter uses if statements to validate user input.
Multiple decisions are handled with both nested if statements and the
case structure (the switch statement).
The debugging features of the IDE are covered, including a step-
by-step exercise that covers stepping through program statements and
checking intermediate values during execution.
Chapter 5, “Menus, Common Dialog Boxes, and Methods,”
covers the concepts of writing and calling general methods. Students
learn to include both menus and context menus in projects, display
common dialog boxes, and use the input provided by the user.
Chapter 6, “Multiform Projects,” adds splash forms and About forms
to a project. Summary data are presented on a separate form.
Chapter 7, “Lists, Loops, and Printing,” incorporates list boxes and
combo boxes into projects, providing the opportunity to discuss looping
procedures and printing lists of information. Printing is accomplished in
.NET using a graphics object and a callback event. The printing controls
also include a Print Preview, which allows students and instructors to
view output without actually printing it.
Chapter 8, “Arrays,” introduces arrays, which follow logically from
the lists covered in Chapter 7. Students learn to use single- and
multidimension arrays, table lookups, structures, and arrays of structures.
Chapter 9, “Web Applications,” introduces programming using
Web Forms, which are used to create Web pages that execute in a
browser application. Students learn to design and develop simple
Web applications. CSS styles and AJAX provide the ability to create
improved, more efficient Web sites.
Chapter 10, “Database Applications,” introduces ADO.NET, which
is Microsoft’s technology for accessing data in a database. This chapter
shows how to create binding sources, table adapters, and datasets.
Programs include accessing data from both Windows Forms and Web
Forms. Students learn to bind data tables to a data grid and bind
individual data fields to controls such as labels and text boxes. LINQ is
used to query an array and a database.
Chapter 11, “Data Files,” presents the techniques for data file
handling. Students learn to save and read small amounts of data using
streams. The StreamWriter and StreamReader objects are used to store
and reload the contents of a combo box.
Chapter 12, “OOP: Creating Object-Oriented Programs,”
explains more of the theory of object-oriented programming. Although we
have been using OOP concepts since Chapter 1, in this chapter students
6 Bradley−Millspaugh: Front Matter Preface © The McGraw−Hill
Programming in Visual C# Companies, 2010
2008

x P R E F A C E

learn the terminology and application of OOP. Inheritance is covered for


visual objects (forms) and for extending existing classes. The samples are
kept simple enough for an introductory class.
Chapter 13, “Graphics, Animation, Sound, and Drag-and-Drop,”
covers the classes and methods of GDI+. The chapter covers graphics
objects, pens, and brushes for drawing shapes and lines. Animation is
accomplished using the Timer control and the SetBounds method for
moving controls. Students learn to play sounds using the SoundPlayer class.
Video files are played using Windows Media Player. Drag-and-drop events
are used to transfer images and the contents of a text box to a list box.
Chapter 14, “Additional Topics in C#,” introduces some advanced
programming topics. This final chapter covers validating user input using
Error Providers and the Validating event of controls. Students learn to
create applications using multiple document interfaces (MDI), create
toolbars and status bars using ToolStrip and StatusStrip controls, and add
Web content to a Windows Form using the WebBrowser control. The
code-snippet feature is introduced. Reading and writing XML text files
are covered. The chapter also covers LINQ to XML.
An introduction to Windows Presentation Framework (WPF) includes
using WPF Interoperability with a standard Windows Form and creating
a WPF Form project.
The appendixes offer important additional material. Appendix A holds
the answers to all Feedback questions. Appendix B covers methods for
dates, math, and string handling. In the OOP programming style, actions
are accomplished with methods of the Math class and String class.
Appendix C gives tips and shortcuts for mastering the Visual Studio
environment, and Appendix D discusses security issues for both Windows
and Web programming.

Thank You
Many people have worked very hard to design and produce this text. We would
like to thank our editors, 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 Robert Price and Peter van der Goes for their thor-
ough technical reviews, constructive criticism, and many valuable suggestions.
Thank you to Theresa Berry for her work on the exercise solutions. And, most
importantly, we are grateful to Dennis and Richard for their support and
understanding through the long days and busy phone lines.

The Authors
We have had fun writing about C#. We hope that this feeling is evident as you
read this book and that you will enjoy learning or teaching this outstanding
programming language.
Julia Case Bradley
Anita C. Millspaugh
Bradley−Millspaugh: Front Matter To the Student © The McGraw−Hill 7
Programming in Visual C# Companies, 2010
2008

TO THE STUDENT

The best way to learn to program in Visual C# is to do it. If you enter and run
the sample projects, you will be on your way to writing applications. Reading
the examples without trying to run them is like trying to learn a foreign lan-
guage or mathematics by just reading about it. Enter the projects, look up your
questions in the extensive MSDN Help files, and make those projects run.

Installing Visual C#
For the programs in this text, you need to install the .NET Framework v 3.5,
Visual C# 2008, and the MSDN (Microsoft Developers Network) library, which
contains all of Help and many instructive articles.
You can download the Express Edition of Visual C# and Visual Web De-
veloper from msdn.microsoft.com/express. Using these two products, you can
complete most of the exercises in this text.

Format Used for Visual C# Statements


Visual C# statements, methods, and functions are shown in this font. Any
values that you must supply are in italics.
As you work your way through this textbook, note that you may see a
subset of the available options for a C# statement or method. Generally, the
options that are included reflect those covered in the chapter. If you want to
see the complete format for any statement or all versions of a method, refer
to Help.
J.C.B.
A.C.M.

xi
8 Notes
Bradley−Millspaugh: 1. Introduction to Text © The McGraw−Hill 9
Programming in Visual C# Programming and Visual Companies, 2010
2008 C# 2008

try
{
//C Convert
H A input
P T values
E R to numeric and assign
quantityInteger = int.Parse(quantityTextBox.T
try
{
1priceDecimal = decimal.Parse(priceTextBox
// Calculate values.
extendedPriceDecimal = quantityInteger *

Introduction to
discountDecimal = Decimal.Round(
(extendedPriceDecimal * DISCOUNT_RATE_
amountDueDecimal = extendedPriceDecimal -
Programming and
totalAmountDecimal += amountDueDecimal;
numberTransactionsInteger++;
Visual C# 2008
// Format and display answers.
extendedPriceTextBox.Text = extendedPrice
at the completion of this chapter, you will be able to . . .

1. Describe the process of visual program design and development.

2. Explain the term object-oriented programming.

3. Explain the concepts of classes, objects, properties, methods, and


events.

4. List and describe the three steps for writing a C# program.

5. Describe the various files that make up a C# project.

6. Identify the elements in the Visual Studio environment.

7. Define design time, run time, and debug time.

8. Write, run, save, print, and modify your first C# program.

9. Identify syntax errors, run-time errors, and logic errors.

10. Look up C# topics in Help.


10 Bradley−Millspaugh: 1. Introduction to Text © The McGraw−Hill
Programming in Visual C# Programming and Visual Companies, 2010
2008 C# 2008

2 V I S U A L C# Introduction to Programming and Visual C# 2008

Writing Windows Applications with Visual C#


Using this text, you will learn to write computer programs that run in the
Microsoft Windows environment. Your projects will look and act like standard
Windows programs. You will use the tools in C# (C sharp) and Windows Forms
to create windows with familiar elements such as labels, text boxes, buttons,
radio buttons, check boxes, list boxes, menus, and scroll bars. Figure 1.1 shows
some sample Windows user interfaces.
Figure 1.1

Graphical user interfaces for


application programs designed
with C# and Windows Forms.
Labels Text boxes

Check box

Radio
buttons

Picture Buttons
box

Labels

Menu bar

Group box
Drop-down list
List box

Beginning in Chapter 9 you will create programs using Web Forms and
Visual Web Developer. You can run Web applications in a browser such as
Internet Explorer or Mozilla FireFox, on the Internet, or on a company intranet.
Figure 1.2 shows a Web Forms application.
You also will become acquainted with Microsoft’s new screen design tech-
nology, Windows Presentation Foundation (WPF), which is covered in Chapter
14. WPF uses its own designer and design elements, which are different from
those used for Windows forms.
Bradley−Millspaugh: 1. Introduction to Text © The McGraw−Hill 11
Programming in Visual C# Programming and Visual Companies, 2010
2008 C# 2008

C H A P T E R 1 3

Figure 1.2

A Web Forms application


running in a browser.

The Windows Graphical User Interface


Microsoft Windows uses a graphical user interface, or GUI (pronounced
“gooey”). The Windows GUI defines how the various elements look and
function. As a C# programmer, you have available a toolbox of these ele-
ments. You will create new windows, called forms. Then you will use the
toolbox to add the various elements, called controls. The projects that you
will write follow a programming technique called object-oriented pro-
gramming (OOP).

Programming Languages—Procedural,
Event Driven, and Object Oriented
There are literally hundreds of programming languages. Each was developed to
solve a particular type of problem. Most traditional languages, such as BASIC,
C, COBOL, FORTRAN, PL/1, and Pascal, are considered procedural lan-
guages. That is, the program specifies the exact sequence of all operations.
Program logic determines the next instruction to execute in response to condi-
tions and user requests.
The newer programming languages such as C#, Java, and Visual Basic
(VB) use a different approach: object-oriented programming (OOP).
In the OOP model, programs are no longer procedural. They do not follow
a sequential logic. You, as the programmer, do not take control and determine
the sequence of execution. Instead, the user can press keys and click various
buttons and boxes in a window. Each user action can cause an event to occur,
which triggers a method (a set of programming statements) that you have writ-
ten. For example, the user clicks on a button labeled Calculate. The clicking
causes the button’s Click event to occur, and the program automatically jumps
to a method you have written to do the calculation.
12 Bradley−Millspaugh: 1. Introduction to Text © The McGraw−Hill
Programming in Visual C# Programming and Visual Companies, 2010
2008 C# 2008

4 V I S U A L C# Introduction to Programming and Visual C# 2008

The Object Model


In C# you will work with objects, which have properties, methods, and events.
Each object is based on a class.

Objects
Think of an object as a thing, or a noun. Examples of objects are forms and
controls. Forms are the windows and dialog boxes you place on the screen;
controls are the components you place inside a form, such as text boxes, but-
tons, and list boxes.

Properties
Properties tell something about or control the behavior of an object such as
its name, color, size, or location. You can think of properties as adjectives that
describe objects. TIP
When you refer to a property, you first name the object, add a period, and The term members is used to refer to
then name the property. For example, refer to the Text property of a form called both properties and methods. ■
SalesForm as SalesForm.Text (pronounced “sales form dot text”).

Methods
Actions associated with objects are called methods. Methods are the verbs of
object-oriented programming. Some typical methods are Close, Show, and
Clear . Each of the predefined objects has a set of methods that you can
use. You will learn to write additional methods to perform actions in your
programs.
You refer to methods as Object.Method (“object dot method”). For exam-
ple, a Show method can apply to different objects: BillingForm.Show shows
the form object called BillingForm; exitButton.Show shows the button object
called exitButton.

Events
You can write methods that execute when a particular event occurs. An event
occurs when the user takes an action such as clicking a button, pressing a key,
scrolling, or closing a window. Events also can be triggered by actions of other
objects, such as repainting a form or a timer reaching a preset point.

Classes
A class is a template or blueprint used to create a new object. Classes contain
the definition of all available properties, methods, and events.
Each time that you create a new object, it must be based on a class. For
example, you may decide to place three buttons on your form. Each button is
based on the Button class and is considered one object, called an instance of the
class. Each button (or instance) has its own set of properties, methods, and
events. One button may be labeled “OK”, one “Cancel”, and one “Exit”. When
the user clicks the OK button, that button’s Click event occurs; if the user clicks
on the Exit button, that button’s Click event occurs. And, of course, you have
written different program instructions for each of the button’s Click events.

An Analogy
If the concepts of classes, objects, properties, methods, and events are still a
little unclear, maybe an analogy will help. Consider an Automobile class. When
Bradley−Millspaugh: 1. Introduction to Text © The McGraw−Hill 13
Programming in Visual C# Programming and Visual Companies, 2010
2008 C# 2008

C H A P T E R 1 5

we say automobile, we are not referring to a particular auto, but we know that
an automobile has a make and model, a color, an engine, and a number of
doors. These elements are the properties of the Automobile class.
Each individual auto is an object, or an instance of the Automobile class.
Each Automobile object has its own settings for the available properties. For
example, each Automobile object has a Color property, such as myAuto.Color =
Blue and yourAuto.Color = Red.
The methods, or actions, of the Automobile class might be Start, SpeedUp,
SlowDown, and Stop. To refer to the methods of a specific object of the class,
use myAuto.Start and yourAuto.Stop.
The events of an Automobile class could be Arrive or Crash. In a C# pro-
gram, you write event-handling methods that specify the actions you want to
take when a particular event occurs for an object. For example, you might write
a method to handle the yourAuto.Crash event.
Note: Chapter 12 presents object-oriented programming in greater depth.

Microsoft’s Visual Studio


The latest version of Microsoft’s Visual Studio, called Visual Studio 2008, in-
cludes C#, Visual C++, Visual Basic, and the .NET 3.5 Framework.

The .NET Framework


The programming languages in Visual Studio run in the .NET Framework. The
Framework provides for easier development of Web-based and Windows-based
applications, allows objects from different languages to operate together, and
standardizes how the languages refer to data and objects. Several third-party
vendors have produced versions of other programming languages to run in the
.NET Framework, including .NET versions of APL by Dyalog, FORTRAN by
Lahey Computer Systems, COBOL by Fujitsu Software Corporation, Pascal by
the Queensland University of Technology (free), PERL by ActiveState, RPG by
ASNA, and Java, known as IKVM.NET.
The .NET languages all compile to (are translated to) a common machine
language, called Microsoft Intermediate Language (MSIL). The MSIL code,
called managed code, runs in the Common Language Runtime (CLR), which is
part of the .NET Framework.

C#
Microsoft C# is a part of Visual Studio. You also can purchase C# by itself
(without the other languages but with the .NET Framework). C# is available in
an Express Edition, a Standard Edition, a Professional Edition, and four
specialized versions of Team System Editions for large enterprise application
development. You can find a matrix showing the features of each edition in
Help. Anyone planning to do professional application development that in-
cludes the advanced features of database management should use the Profes-
sional Edition or the Team System Database version. The full Professional
Edition is available to educational institutions through the Microsoft Academic
Alliance program and is the best possible deal. When a campus department
purchases the Academic Alliance, the school can install Visual Studio on all
classroom and lab computers and provide the software to all students and fac-
ulty at no additional charge. For more information, have your instructor visit:
http://msdn.microsoft.com/en-us/academic/default.aspx
14 Bradley−Millspaugh: 1. Introduction to Text © The McGraw−Hill
Programming in Visual C# Programming and Visual Companies, 2010
2008 C# 2008

6 V I S U A L C# Introduction to Programming and Visual C# 2008

Microsoft provides an Express Edition of each of the programming lan-


guages, which you can download for free (www.microsoft.com/express/down-
load/). You can use Visual C# Express for Windows development and Visual
Web Developer Express for the Web applications in Chapters 9 and 10.
This text is based on the Professional Edition of Visual Studio 2008, the
current version. You cannot run the projects in this text in any earlier version
of C#.

Writing C# Programs
When you write a C# application, you follow a three-step process for planning
the project and then repeat the three-step process for creating the project. The
three steps involve setting up the user interface, defining the properties, and
then creating the code.

The Three-Step Process


Planning
1. Design the user interface. When you plan the user interface, you draw
a sketch of the screens the user will see when running your project. On
your sketch, show the forms and all the controls that you plan to use.
Indicate the names that you plan to give the form and each of the objects
on the form. Refer to Figure 1.1 for examples of user interfaces.
Before you proceed with any more steps, consult with your user and
make sure that you both agree on the look and feel of the project.
2. Plan the properties. For each object, write down the properties that you
plan to set or change during the design of the form.
3. Plan the C# code. In this step you plan the classes and methods that
will execute when your project runs. You will determine which events
require action to be taken and then make a step-by-step plan for those
actions.
Later, when you actually write the C# code, you must follow the
language syntax rules. But during the planning stage, you will write out
the actions using pseudocode, which is an English expression or
comment that describes the action. For example, you must plan for
the event that occurs when the user clicks on the Exit button. The
pseudocode for the event could be End the project or Quit.

Programming
After you have completed the planning steps and have approval from your user,
you are ready to begin the actual construction of the project. Use the same
three-step process that you used for planning.
1. Define the user interface. When you define the user interface, you create
the forms and controls that you designed in the planning stage.
Think of this step as defining the objects you will use in your
application.
Bradley−Millspaugh: 1. Introduction to Text © The McGraw−Hill 15
Programming in Visual C# Programming and Visual Companies, 2010
2008 C# 2008

C H A P T E R 1 7

2. Set the properties. When you set the properties of the objects, you give
each object a name and define such attributes as the contents of a label,
the size of the text, and the words that appear on top of a button and in
the form’s title bar.
You might think of this step as describing each object.
3. Write the code. You will use C# programming statements (called C#
code) to carry out the actions needed by your program. You will be sur-
prised and pleased by how few statements you need to create a powerful
Windows program.
You can think of this third step as defining the actions of your
program.

C# Application Files
A C# application, called a solution, can consist of one or more projects. Since
all of the solutions in this text have only one project, you can think of one
solution = one project. Each project can contain one or more form files. In
Chapters 1 through 5, all projects have only one form, so you can think of one
project = one form. Starting in Chapter 6, your projects will contain multiple
forms and additional files. As an example, the HelloWorld application that you
will create later in this chapter creates the following files:

File Name File Icon Description

HelloWorld.sln The solution file. A text file that holds


information about the solution and the projects
it contains. This is the primary file for the
solution—the one that you open to work on or
run your project. Note the “9” on the icon,
which refers to Visual Studio version 9.

HelloWorld.suo Solution user options file. Stores information


about the state of the integrated development
environment (IDE) so that all customizations
can be restored each time you open the
solution.

HelloForm.cs A .cs (C#) file that holds the code methods that
you write. This is a text file that you can open
in any editor. Warning: You should not modify
this file unless you are using the editor in the
Visual Studio environment.

HelloForm.Designer.cs A .cs (C#) file created by the Form Designer


that holds the definition of the form and its
controls. You should not modify this file
directly, but instead make changes in the
Designer and allow it to update the file.

HelloForm.resx A resource file for the form. This text file


defines all resources used by the form,
including strings of text, numbers, and any
graphics.
16 Bradley−Millspaugh: 1. Introduction to Text © The McGraw−Hill
Programming in Visual C# Programming and Visual Companies, 2010
2008 C# 2008

8 V I S U A L C# Introduction to Programming and Visual C# 2008

File Name File Icon Description

HelloWorld.csproj The project file that describes the project and


lists the files that are included in the project.

HelloWorld.csproj.user The project user options file. This text file


holds IDE option settings so that the next time
you open the project, all customizations will be
restored.

Program.cs A .cs (C#) file that contains automatically


generated code that runs first when you execute
your application.

Note: You can display file extensions. In Windows Vista, open the Explorer and
select Organize / Folders and Search Options, click on the View tab and deselect
the check box for Hide extensions for known file types. In Windows XP, in the My
Computer Tools menu, select Folder Options and the View tab. Deselect the
check box for Hide extensions for known file types. If you do not display the
extensions, you can identify the file types by their icons.
After you run your project, you will find several more files created by the
system. The only file that you open directly is the .sln, or solution file.

The Visual Studio Environment


The Visual Studio environment is where you create and test your projects.
A development environment such as Visual Studio is called an integrated
development environment (IDE). The IDE consists of various tools, includ-
ing a form designer, which allows you to visually create a form; an editor, for
entering and modifying program code; a compiler, for translating the C# state-
ments into the intermediate machine code; a debugger, to help locate and cor-
rect program errors; an object browser, to view the available classes, objects,
properties, methods, and events; and a Help facility.
In versions of Visual Studio prior to .NET, each language had its own IDE.
For example, to create a Visual Basic project you would use the Visual Basic
IDE, and to create a C++ project you would use the C++ IDE. But in Visual
Studio, you use the one IDE to create projects in any of the supported
languages.

Default Environment Settings


The full version of Visual Studio 2008 provides an option that allows the
programmer to select the default profile for the IDE. The first time you open
Visual Studio, you are presented with the Choose Default Environment Settings
dialog box (Figure 1.3), where you can choose Visual C# Development Settings.
This text uses the Visual C# settings.
Bradley−Millspaugh: 1. Introduction to Text © The McGraw−Hill 17
Programming in Visual C# Programming and Visual Companies, 2010
2008 C# 2008

C H A P T E R 1 9

Figure 1.3

The first time you open the


Visual Studio IDE, you must
select the default environment
settings for Visual C#
development.

Note: If you plan to develop in more than one language, such as VB and
C#, you can save each group of settings and switch back and forth between the
two. Select Tools / Import and Export Settings and choose to Reset all settings.

The IDE Initial Screen


When you open the Visual Studio IDE, you generally see an empty environ-
ment with a Start Page (Figure 1.4). However, it’s easy to customize the envi-
ronment, so you may see a different view. In the step-by-step exercise later in
this chapter, you will learn to reset the IDE layout to its default view.
The contents of the Start Page vary, depending on whether you are con-
nected to the Internet. Microsoft has included links that can be updated, so you
may find new and interesting information on the Start Page each time you open
it. To display or hide the Start Page, select View / Other Windows / Start Page.
You can open an existing project or begin a new project using the Start
Page or the File menu. The examples in this text use the menus.

The New Project Dialog


You will create your first C# projects by selecting File / New Project, which
opens the New Project dialog (Figure 1.5). In the New Project dialog, you may
need to expand the node for Other Languages, depending on your installation.
Under Visual C#, select Windows, and in the Templates pane, select Windows
Forms Application. You also give the project a name in this dialog. Deselect the
check box for Create directory for solution, which creates an extra level of folders
for our single-project solutions.
18 Bradley−Millspaugh: 1. Introduction to Text © The McGraw−Hill
Programming in Visual C# Programming and Visual Companies, 2010
2008 C# 2008

10 V I S U A L C# Introduction to Programming and Visual C# 2008

Figure 1.4

The Visual Studio IDE with the Start Page open, as it first appears in Windows Vista, without an open project. You can close
the Start Page by clicking on its Close button.
Close button for
Start Page

Figure 1.5

Select the Windows Forms Begin a new C# Windows


Application template project using the Windows
Forms Application template.

Enter the project name


Select Visual C# Windows
Bradley−Millspaugh: 1. Introduction to Text © The McGraw−Hill 19
Programming in Visual C# Programming and Visual Companies, 2010
2008 C# 2008

C H A P T E R 1 11

The IDE Main Window


Figure 1.6 shows the Visual Studio environment’s main window and its various
child windows. Note that each window can be moved, resized, opened, closed, and
customized. Some windows have tabs that allow you to display different contents.
Your screen may not look exactly like Figure 1.6; in all likelihood, you will want
to customize the placement of the various windows. The Designer and Editor win-
dows are generally displayed in tabs in the center of the screen (the Document
window), and the various tool windows are docked along the edges and bottom of
the IDE, but the locations and the docking behavior are all customizable.
The IDE main window holds the Visual Studio menu bar and the toolbars.
You can display or hide the various windows from the View menu.
Figure 1.6

The Visual Studio environment. Each window can be moved, resized, closed, or customized.

The Toolbars
You can use the buttons on the toolbars as shortcuts for frequently used opera-
tions. Each button represents a command that also can be selected from a menu.
Figure 1.7a shows the toolbar buttons on the Standard toolbar for the Profes-
sional Edition, which displays in the main window of the IDE; Figure 1.7b shows
the Layout toolbar, which is useful for designing forms in the Form Designer; and
Figure 1.7c shows the Text Editor toolbar, which contains buttons to use in the
Editor window. Select View / Toolbars to display or hide these and other toolbars.
20 Bradley−Millspaugh: 1. Introduction to Text © The McGraw−Hill
Programming in Visual C# Programming and Visual Companies, 2010
2008 C# 2008

12 V I S U A L C# Introduction to Programming and Visual C# 2008

Figure 1.7

The Visual Studio toolbars contain buttons that are shortcuts for menu commands. You can display or hide each of the
toolbars: a. the Standard toolbar; b. the Layout toolbar; and c. the Text Editor toolbar.
Ne
Ad Pro
Op Ne t
Sa en F Ite
Sa F
Cu e A e
Co t
Pa y
Unste
Re
Na
Na igat

So

So

Fi

So
Pr utio
Ob er x
To ject ies lor
St lbo Bro ind r
ar x ws o
nd

op n E

o
ve ile m
v il

lu

lu

l
p
w

do
v
vi e B
d jec

do

tP
tio

tio
ga a

t p

ag
te ck

n
ll
w

Co

Pl

e
Fo wa

W e
at
nf
rw rd

fo

er w
ig
ar

rm
ur
d

s
at
io
(a)

ns
Al

Al
Al Le
Al C
Al Rig rs
Al To
Al Mi
M Bo es
M e Sa ms
M e Sa e W
Si Sa e H th
M o G Siz t
In Ho
De ease zon
Re reas ori Sp

M ve H oriz tal S g E
In e
De ease cal l Sp cin
Re eas erti acin ing
Ce ve erti Spa qu
Ce er H tic Sp g

Br r Ve zont aci g
Se o
M oB t
Ta e Ce k
ig

ig
ig ft
ig en
ig
ig ps
ig dd
ak tto
ak m
ak m id
ze m ei
ak ri e

ak

er
cr ri

cr rti nta pa g

b
in rti al ng
nd Fr ly
nt Ver cal cin al
nt or al S aci
c H tal
m e H zon aci

cr V Sp ac g
m e V cal g E
n

n
n
n te
n hts
n
n

g ac
Or lls
e

e V oriz nta pac ual

g T ca ly
o

e i
T e gh

T
to

de
Gr

r
s
id

on
o

l
o

p n
l S
n

i n
q

(b)

Co Un
Di
Di play
Di lay bje
Di lay aram Me
De lay uic eter ber
In reas ord Info fo ist

M le
M e To ook
M ve T Pre ark
M e T Ne ous
M e T Pre Bo ook
M e T Nex ous ma ark
Cl e T Prev Boo ook
To

m co
ov B
o
ov o vi
ov o xt B
ov o vi ok m
ov o t B rk

m m
cr e C

ea o N io km m
s
sp O
sp P ct
sp Q

gg
c W

en m
ea In om

r B e us a ark

t O en
se de p

oo xt B Bo rk i in

ut t th
In nt let

km oo ok n C
de

th e
m

ar km ma Cu urr
k

nt

e S Se
ks a rk rre en

el lec
m

ec te
In L

te d
rk i n t
io

d Li
n

Li ne
in n C t F Fol

ne s
Cu ur old de

s
rre ren er r
nt t D
Do oc
cu um
m en
en t
t

(c)

The Document Window


The largest window in the center of the screen is the Document window. TIP
Notice the tabs across the top of the window, which allow you to switch between Use Ctrl + Tab to switch to another
open documents. The items that display in the Document window include the open document in the Document
Form Designer, the Code Editor, the Project Designer, the Database Designer, window. ■
and the Object Browser.
You can switch from one tab to another, or close any of the documents
using its Close button.

The Form Designer


The Form Designer is where you design a form that makes up your user in-
terface. In Figure 1.6, the Form Designer for Form1 is currently displaying.
You can drag the form’s sizing handles or selection border to change the size of
the form.
Bradley−Millspaugh: 1. Introduction to Text © The McGraw−Hill 21
Programming in Visual C# Programming and Visual Companies, 2010
2008 C# 2008

C H A P T E R 1 13

When you begin a new C# Windows application, a new form is added to


the project with the default name Form1. In the step-by-step exercise later in
the chapter, you will learn to change the form’s name.

The Solution Explorer Window


The Solution Explorer window holds the filenames for the files included in
your project and a list of the classes it references. The Solution Explorer window
and the environment’s title bar hold the name of your solution (.sln) file, which is
WindowsFormsApplication1 by default unless you give it a new value in the New
Project dialog box. In Figure 1.6, the name of the solution is MyFirstProject.

The Properties Window


You use the Properties window to set the properties for the objects in your TIP
project. See “Set Properties” later in this chapter for instructions on changing You can sort the properties in the
properties. window either alphabetically or by
categories. Use the buttons on the
Properties window. ■
The Toolbox
The toolbox holds the tools you use to place controls on a form. You may have
more or different tools in your toolbox, depending on the edition of C# you are
using (Express, Standard, Professional, or Team System). Figure 1.8 shows the
toolbox.
Figure 1.8

The toolbox for Visual Studio


Windows Forms. Your toolbox
may have more or fewer tools,
Common controls for
Windows Forms depending on the edition you
are using.

TIP
You can sort the tools in the tool-
box: Right-click the toolbox and se-
lect Sort Items Alphabetically from
the context menu (the shortcut
menu). ■

Scroll to see more


controls
Random documents with unrelated
content Scribd suggests to you:
THE BOA AFTER A MEAL.

The Snake evidently only embraced him in a kill-him-when-I-want-


him manner, just firmly enough to prevent an escape—but her lips
were glued on his, in a close “Judas’ kiss.” So long a time elapsed, in
this position, both as marble-still as poor old Laocoon with his
leaches on, that I really began to doubt the tale of the Boa’s ability
in swallowing; and to associate the hoax before me, with that of the
Bottle Conjuror. The head of the snake, in fact, might have gone
without difficulty into a wine-glass, and the throat, down which the
rabbit was to proceed whole, seemed not at all thicker than my
thumb. In short, I thought the reported cram was nothing but stuff,
and the only other visitor declared himself of my opinion: “If that
’ere little wiper swallows up the rabbit, I’ll bolt um both!” and he
seemed capable of the feat. He looked like a personification of what
Political Economists call the Public Consumer; or, Geoffrey Crayon’s
Stout Gentleman, seen through Carpenter’s Solar Microscope; a
genuine Edax Rerum; one of your devourers of legs of mutton and
trimmings, for wagers: the delight of eating-houses, and the dread
of ordinaries. The contrast was whimsical, between his mountain of
mummy, and the slim Macaroni figure of the Snake, the reputed
Glutton. However, the Boa began at last to prepare for the meal, by
lubricating the muzzle of the Rabbit with her slimy tongue, and then
commenced in earnest,

As far as in her lay to take him in,


A stranger dying with so fair a skin.

The process was tedious—“one swallow makes a summer”—but it


gradually became apparent, from the fate of the head, that the
whole body might eventually be “lost in the Serpentine.” The Reptile,
indeed, made ready for the rest of the interment by an operation
rather horrible. On a sudden, the living cable was observed, as a
sailor would say, to haul in her slack, and with a squeeze evincing
tremendous muscular power, she reduced the whole body into a
compass that would follow the head with perfect ease. It was like a
regular smash in business:—the poor rabbit was completely broken—
and the wily winder-up of his affairs recommenced paying herself in
full. It was a sorry sight and sickening. As for the Stout Gentleman,
he could not control his agitation. His eyes rolled and watered; his
jaws constantly yawned like a panther’s; and his hands with a
convulsive movement were clasped every now and then on his
stomach;—but when the whole rabbit was smothered in snake, he
could restrain himself no longer, and rushed out of the menagerie as
if he really expected to be called upon to fulfil his rash engagement.
Anxious to ascertain the true nature of the impulse, I hurried in
pursuit of him, and after a short but sharp chase, I saw him dash
into the British Hotel, and overheard his familiar voice—the same
that had promised to swallow both Snake and Snack—bellowing out,
guttural with hunger—“Here!—waiter!—Quick!—Rabbits in onions for
two!”

THE GREAT SEA SERPENT DISCOVERED FROM THE MAST-HEAD.


A STORM AT HASTINGS
AND THE LITTLE UNKNOWN.

’TWAS August—Hastings every day was filling—


Hastings, that “greenest spot on memory’s waste!”
With crowds of idlers willing or unwilling
To be bedipped—be noticed—or be braced,
And all things rose a penny in a shilling.
Meanwhile, from window and from door, in haste
“Accommodation bills” kept coming down,
Gladding “the world of letters” in that town.

Each day pour’d in new coach-fulls of new cits,


Flying from London smoke and dust annoying,
Unmarried Misses hoping to make hits,
And new-wed couples fresh from Tunbridge toying.
Lacemen and placemen, ministers and wits,
And Quakers of both sexes, much enjoying
A morning’s reading by the ocean’s rim,
That sect delighting in the sea’s broad brim.
AN ABRIDGMENT OF ALL THAT IS PLEASANT IN MAN.
And lo! amongst all these appear’d a creature,
So small, he almost might a twin have been,
With Miss Crachami—dwarfish quite in stature,
Yet well proportion’d—neither fat nor lean,
His face of marvellously pleasant feature.
So short and sweet a man was never seen—
All thought him charming at the first beginning—
Alas, ere long they found him far too winning!

He seem’d in love with chance—and chance repaid


His ardent passion with her fondest smile,
The sunshine of good luck, without a shade,
He staked and won—and won and staked—the bile
It stirr’d of many a man and many a maid,
To see at every venture how that vile
Small gambler snatch’d—and how he won them too—
A living Pam, omnipotent at loo!
A TIDE-WAITER.
Miss Wiggins set her heart upon a box,
’Twas handsome, rosewood, and inlaid with brass,
And dreamt three times she garnish’d it with stocks,
Of needles, silks, and cottons—but alas!
She lost it wide awake.—We thought Miss Cox
Was lucky—but she saw three caddies pass
To that small imp:—no living luck could loo him!
Sir Stamford would have lost his Raffles to him!

And so he climb’d—and rode, and won—and walk’d,


The wondrous topic of the curious swarm
That haunted the Parade. Many were balk’d
Of notoriety by that small form
Pacing it up and down:—some even talk’d
Of ducking him—when lo! a dismal storm
Stepp’d in—one Friday, at the close of day—
And every head was turn’d another way—

Watching the grander guest. It seem’d to rise


Bulky and slow upon the southern brink
Of the horizon—fann’d by sultry sighs—
So black and threatening, I cannot think
Of any simile, except the skies
Miss Wiggins sometime shades in Indian ink—
Miss-shapen blotches of such heavy vapour,
They seem a deal more solid than her paper.

As for the sea, it did not fret, and rave,


And tear its waves to tatters, and so dash on
The stony-hearted beach;—some bards would have
It always rampant, in that idle fashion,—
Whereas the waves roll’d in, subdued and grave,
Like schoolboys, when the master’s in a passion,
Who meekly settle in and take their places,
With a very quiet awe on all their faces.
Some love to draw the ocean with a head,
Like troubled table-beer,—and make it bounce,
And froth and roar, and fling—but this, I’ve said,
Surged in scarce rougher than a lady’s flounce:—
But then, a grander contrast thus it bred
With the wild welkin, seeming to pronounce
Something more awful in the serious ear,
As one would whisper that a lion’s near—

Who just begins to roar; so the hoarse thunder


Growl’d long—but low—a prelude note of death,
As if the stifling clouds yet kept it under,
But still it mutter’d to the sea beneath
Such a continued peal, as made us wonder
It did not pause more oft to take its breath,
Whilst we were panting with the sultry weather,
And hardly cared to wed two words together,

But watch’d the surly advent of the storm,


Much as the brown-cheek’d planters of Barbadoes
Must watch a rising of the Negro swarm:—
Meantime it steer’d, like Odin’s old Armadas,
Right on our coast;—a dismal, coal-black form;—
Many proud gaits were quell’d—and all bravadoes
Of folly ceased—and sundry idle jokers
Went home to cover up their tongs and pokers.

So fierce the lightning flashed. In all their days


The oldest smugglers had not seen such flashing,
And they are used to many a pretty blaze,
To keep their Hollands from an awkward clashing
With hostile cutters in our creeks and bays:—
And truly one could think without much lashing
The fancy, that those coasting clouds so awful
And black, were fraught with spirits as unlawful.

The gay Parade grew thin all the fair crowd


The gay Parade grew thin—all the fair crowd
Vanish’d—as if they knew their own attractions,—
For now the lightning through a near hand cloud
Began to make some very crooked fractions—
Only some few remain’d that were not cow’d,
A few rough sailors, who had been in actions,
And sundry boatmen, that with quick yeo’s,
Lest it should blow,—were pulling up the Rose:

(No flower, but a boat)—some more hauling


The Regent by the head:—another crew
With that same cry peculiar to their calling—
Were heaving up the Hope:—and as they knew
The very gods themselves oft get a mauling
In their own realms, the seamen wisely drew
The Neptune rather higher on the beach,
That he might lie beyond his billows’ reach.

And now the storm, with its despotic power


Had all usurp’d the azure of the skies,
Making our daylight darker by an hour,
And some few drops—of an unusual size—
Few and distinct—scarce twenty to the shower,
Fell like huge tear-drops from a Giant’s eyes—
But then this sprinkle thicken’d in a trice
And rain’d much harder—in good solid ice.

Oh! for a very storm of words to show


How this fierce crash of hail came rushing o’er us!
Handel would make the gusty organs blow
Grandly, and a rich storm in music score us!—
But ev’n his music seem’d composed and low,
When we were handled by this Hailstone Chorus;
Whilst thunder rumbled, with its awful sound,
And frozen comfits roll’d along the ground—

As big as bullets:—Lord! how they did batter


Our crazy tiles:—And now the lightning flash’d
Alternate with the dark, until the latter
Was rarest of the two:—the gust too dash’d
So terribly, I thought the hail must shatter
Some panes,—and so it did—and first it smash’d
The very square where I had chose my station
To watch the general illumination.

Another, and another, still came in,


And fell in jingling ruin at my feet,
Making transparent holes that let me win
Some samples of the storm:—Oh! it was sweet
To think I had a shelter for my skin,
Culling them through these “loopholes of retreat”—
Which in a little we began to glaze—
Chiefly with a jacktowel and some baize!

By which, the cloud had pass’d o’erhead, but play’d


Its crooked fires in constant flashes still,
Just in our rear, as though it had array’d
Its heavy batteries at Fairlight Mill,
So that it lit the town, and grandly made
The rugged features of the Castle Hill
Leap, like a birth, from chaos, into light,
And then relapse into the gloomy night—

As parcel of the cloud:—the clouds themselves,


Like monstrous crags and summits everlasting,
Piled each on each in most gigantic shelves,
That Milton’s devils were engaged in blasting.—
We could e’en fancy Satan and his elves
Busy upon those crags, and ever casting
Huge fragments loose—and that we felt the sound
They made in falling to the startled ground.

And so the tempest scowl’d away,—and soon,


Timidly shining through its skirts of jet,
dy s g t oug ts s ts o jet,
We saw the rim of the pacific moon,
Like a bright fish entangled in a net,
Flashing its silver sides,—how sweet a boon,
Seem’d her sweet light, as though it would beget,
With that fair smile, a calm upon the seas—
Peace in the sky—and coolness in the breeze!

Meantime the hail had ceased:—and all the brood


Of glaziers stole abroad to count their gains;—
At every window, there were maids who stood
Lamenting o’er the glass’s small remains,—
Or with coarse linens made the fractious good,
Stanching the wind in all the wounded panes,—
Or, holding candles to the panes, in doubt:
The wind resolved—blowing the candles out.

No house was whole that had a southern front,—


No green-house but the same mishap befell:—
Bow-windows and bell-glasses bore the brunt,—
No sex in glass was spared!—For those who dwell
On each hill side, you might have swam a punt
In any of their parlours;—Mrs. Snell
Was slopp’d out of her seat,—and Mr. Hitchin
Had a flow’r-garden wash’d into a Kitchen.
SHE FROM OCEAN RISING.
But still the sea was mild, and quite disclaim’d
The recent violence.—Each after each
The gentle waves a gentle murmur framed,
Tapping, like Woodpeckers, the hollow beach.
Howbeit his weather eye the seaman aim’d
Across the calm, and hinted by his speech
A gale next morning—and when morning broke
There was a gale—“quite equal to bespoke.”

Before high water—(it were better far


To christen it not water then, but waiter,
For then the tide is serving at the bar)
Rose such a swell—I never saw one greater!
Black, jagged billows rearing up in war
Like ragged roaring bears against the baiter,
With lots of froth upon the shingle shed,
Like stout pour’d out with a fine beachy head.

No open boat was open to a fare,


Or launch’d that morn on seven-shilling trips;
No bathing woman waded—none would dare
A dipping in the wave—but waived their dips;
No seagull ventured on the stormy air,
And all the dreary coast was clear of ships;
For two lea shores upon the river Lea
Are not so perilous as one at sea.

Awe-struck we sat, and gazed upon the scene


Before us in such horrid hurly-burly,—
A boiling ocean of mix’d black and green,
A sky of copper colour, grim and surly,—
When lo, in that vast hollow scoop’d between
Two rolling Alps of water,—white and curly!
We saw a pair of little arms a-skimming,
Much like a first or last attempt at swimming!
Sometimes a hand—sometimes a little shoe—
Sometimes a skirt—sometimes a hank of hair,
Just like a dabbled seaweed, rose to view,
Sometimes a knee, sometimes a back was bare—
At last a frightful summerset he threw
Right on the shingles. Any one could swear
The lad was dead—without a chance of perjury,
And batter’d by the surge beyond all surgery!

However, we snatch’d up the corse thus thrown,


Intending, Christian-like, to sod and turf it,
And after venting Pity’s sigh and groan,
Then Curiosity began with her fit;
And lo! the features of the Small Unknown!
’Twas he that of the surf had had this surfeit!—
And in his fob, the cause of late monopolies!
We found a contract signed Mephistopheles!

A bond of blood, whereby the sinner gave


His forfeit soul to Satan in reversion,
Providing in this world he was to have
A lordship over luck, by whose exertion
He might control the course of cards, and brave
All throws of dice,—but on a sea excursion
The juggling Demon, in his usual vein,
Seized the last cast—and Nick’d him in the main!
LINES
TO A LADY ON HER DEPARTURE FOR INDIA.

Go where the waves run rather Holborn-hilly,


And tempests make a soda-water sea,
Almost as rough as our rough Piccadilly,
And think of me!

Go where the mild Madeira ripens her juice,—


A wine more praised that it deserves to be:
Go pass the Cape, just capable of ver-juice,
And think of me!
KETCHING ITS PREY.
Go where the Tiger in the darkness prowleth
Making a midnight meal of he and she;
Go where the Lion in his hunger howleth,
And think of me!

Go where the serpent dangerously coileth,


Or lies along at full length like a tree,
Go where the Suttee in her own soot broileth,
And think of me!

Go where with human notes the Parrot dealeth


In mono-polly-logue with tongue as free,
And like a woman, all she can revealeth,
And think of me!

Go to the land of muslin and nankeening,


And parasols of straw where hats should be,
Go to the land of slaves and palankeening,
And think of me!

Go to the land of Jungles and of vast hills,


And tall bamboos—may none bamboozle thee!
Go gaze upon their Elephants and Castles,
And think of me!

Go where a cook must always be a currier,


And parch the pepper’d palate like a pea,
Go where the fierce musquito is a worrier,
And think of me!
“A SOW WESTER OFF THE CAPE:—PIGS IN THE TROUGH OF THE SEA.”

Go where the maiden on a marriage plan goes,


Consign’d for wedlock to Calcutta’s quay,
Where woman goes for mart, the same as mangoes,
And think of me!

Go where the sun is very hot and fervent,


Go to the land of pagod and rupee,
Where every black will be your slave and servant,
And think of me!
THE NELSON.
This here, your honour, upon wheels, is the true genuine real Nelson’s Car.
GUIDE TO GREENWICH HOSPITAL.

“THE Nelson,” I repeated to myself, as I read that illustrious name


on the dicky of the vehicle—“the Nelson.” My fancy instantly
converted the coach into a first-rate, the leaders and wheelers into
sea-horses, the driver into Neptunus, brandishing a trident, and the
guard into a Triton blowing his wreathed shell. There was room for
one on the box, so I climbed up, and took my seat beside the
coachman. “Now, clap on all sail,” said I, audibly, “I am proud to be
one of the crew of the great Nelson, the hero of Aboukir.”
“Begging your pardon, Sir,” said the coachman, “the Hero ain’t a
booker at Mrs. Nelson’s: it goes from some other yard.” Gracious
powers! what a tumble down stairs for an idea! As for mine, it
pitched on its head, as stunned and stupefied as if it had rolled
down the whole flight at the Monument. “I have made a Bull,
indeed,” I exclaimed, as the noted inn at Aldgate occurred to my
memory; “but we are the slaves of association,” I continued,
addressing the coachman, “and the name of Nelson identified itself
with the Union Jack.”
“I really can’t say,” replied the coachman, very civilly, “whether
the name of Mrs. Nelson is down to the Slave Associations or not:
but as for Jack, if you mean Jack Bunce, he’s been off the Union
these six months. Too fond of the Bar, Sir” (here he tipped me the
most significant of winks), “to keep his seat on the Bench.”
“I alluded, my good fellow, to Nelson, the wonder of the
maritime world—the dauntless leader when yard was opposed to
yard, and seas teemed with blood.”
“We’re all right—as right as a trivet,” said the coachman, after a
pause of perplexity; “I thought our notions were getting rather wide
apart, and that one of us wanted putting straight; but I see what
you mean, and quite go along with your opinion, step for step. To be
sure, Mrs. Nelson has done the world and all for coaching; and the
Wonder is the crack of all the drags in London, and so is the
Dauntless, let yard turn out agin yard, as you say, any day you like.
And as for leaders, and teams full of blood, there’s as pretty a
sprinkling of blood in the tits I’m now tooling of—”
“The vehicles of the proprietress, and the appearance of the
animals, with their corresponding caparisons,” said I, “have often
gratified my visual organs and elicited my mental plaudits.”
“That’s exactly what I says,” replied the coachman, very briskly,
“there’s no humbug nor no nonsense about Mrs. Nelson. You never
see her a standing a-foaming and fretting in front o’ the Bank, with a
regular mob round her, and looking as if she’d bolt with the
Quicksilver. And you never see her painted all over her body,
wherever there’s room for ’em, with Saracen Heads, and Blue Boars,
and Brown Bears, from her roller bolts to her dicky and hind boot.
She’s plain and neat, and nothin’ else—and is fondest of having her
body of a claret colour, pick’d out with white, and won’t suffer the
Bull, no where, except on the back-gammon board.”
I know not how much further the whimsical description might
have gone, if a strapping, capless, curly-headed lass, running with all
her might and main, had not addressed a screaming retainer to the
coachman. With some difficulty he pulled up, for he had been tacitly
giving me a proof that the craft of his Nelson was a first-rate, with
regard to its rate of travelling.
“If you please, Mr. Stevens,” said the panting damsel, holding up
something towards the box—“if you please, Mr. Stevens, mother’s
gone to Lonnon—in the light cart—and will you be so kind as to give
her—her linchpin.”
Mr. Stevens took the article with a smile, and I fancied with a sly
squeeze of the hand that delivered it.
“If such a go had been anyone’s but your mother’s, Fanny,” he
slyly remarked, “I should have said it was somebody in love.” The
Dispatch was too strictly timed to allow of further parley; the horses
broke, or were rather broken, into a gallop, in pursuit of the mother
of Fanny, the Flower of Waltham; and the pin secretly acting as a
spur, we did the next five mile in something like twenty minutes.
In spite, however, of this unusual speed, we never overtook Mrs.
Merryweather and her cart till we arrived at the Basing-House,
where we found her chirping over a cup of ale; as safe and sound as
if linchpins had never been invented; in fact, she made as light of
the article, when it was handed to her, as if it had been only a pin
out of her gown!
FANCY PORTRAIT—MRS. NELSON.

“Well, I must say one thing for Mrs. Nelson,” said our coachman,
as he resumed his seat on the box, “and that’s this. There’s no
pinning at the Bull. She sets her face against everything but the
patent boxes. She may come to a runaway with a bolter—or drop
the ribbons—or make a mistake in clearing a gate, by being a little
lushy—but you’ll never see Mrs. Nelson lying flat on her side in the
middle of the road, with her insides gone to smash, and her outsides
well distributed, because she’s been let go out of the yard without
one of her pins.”
THE STAMP DUTY ON SCOTCH LINEN.

SONNET
TO A SCOTCH GIRL, WASHING LINEN AFTER HER
COUNTRY FASHION.
WELL done and wetly, thou Fair Maid of Perth,
Thou mak’st a washing picture well deserving
The pen and pencilling of Washington Irving:
Like dripping Naiad, pearly from her birth,
Dashing about the water of the Firth,
To cleanse the calico of Mrs. Skirving,
And never from thy dance of duty swerving
As there were nothing else than dirt on earth!
Yet what is thy reward? Nay, do not start!
I do not mean to give thee a new damper,
But while thou fillest this industrious part
Of washer, wearer, mangler, presser, stamper,
Deserving better character—thou art
What Bodkin would but call—“a common tramper.”
MY APOLOGY.
GENTLE READERS,
For the present month, there must be what Dr. Johnson called
a solution of continuity in my “Literary Reminiscences.” Confined to
my chamber by what ought to be termed roomatism—then attacked
by my old livery complaint—and finally, by a minor, but troublesome
malady, the Present has too much prevailed over the Past, to let me
indulge in any retrospective reviews. In such cases, on the stage,
when a Performer is unable to support his character, a substitute is
usually found to read the part; but, unfortunately, in the present
case there is no part written, and consequently it cannot be read.
But apropos of theatricals—there is an anecdote on point.
In the Olympic days of the great Elliston, there was one evening
a tremendous tumult at his Theatre, in consequence of the absence
of a favourite performer. One man in the pit—a Butcher—was
especially vociferous in his cry for “Carl! Carl! Carl!” Others called for
the Manager, who duly made his appearance, and black as the
weather looked, he was the very sort of pilot to weather the storm.
With one of his princely bows he proceeded to address the House.
“Ladies and Gentlemen—but by your leave I will address myself to a
single individual. I will ask that gentleman (pointing to the vociferous
Butcher) what right he has to demand the appearance of Mr. Carl?”
“’Cos,” said the Butcher, “’cos he’s down in the Bill.” Such an
undeniable answer would have staggered any other Manager than
Elliston, but he was not easily to be disconcerted. “Because he is
down in the bill!” he echoed, in a tone of the loftiest indignation:
“Ladies and Gentlemen, the Mr. Carl, so unseasonably, so
vociferously and so unfeelingly called for, is at this very moment
labouring under severe illness—he is in bed. And let me ask, is a
man, a fellow-creature, a human being, to be torn from his couch,
from his home, on a cold night, from the affectionate attentions of
his wife and family, at the risk of his valuable life perhaps, to go
through a fatiguing part because he happens to be DOWN IN THE
BILL?” [Cries of “Shame, shame!” from all parts of the house.] “And
yet, ladies and gentlemen, there stands a man—if I may call him so
—a Butcher, that for his own selfish gratification—the amusement of
a few short hours—would risk the very existence of a deserving
member of society, a good husband, father, friend, and one of your
favourite actors, and all, forsooth, because he is DOWN IN THE
BILL!” [Universal hooting, with cries of “Turn him out.”] “By all
means,” acquiesced the Manager, with one of his best bows—and
the indignant pittites actually hooted and kicked their own champion
out of the theatre, as something more than a Butcher, and less than
a Christian.
Now I am myself, gentle readers, in the same predicament with
Mr. Carl. Like him I am an invalid—and like him I am unfortunately
down in the Bill. It would not become me to set forth my own
domestic or social virtues, or to hint what sort of gap my loss would
make in society—still less would it consist with modesty to compare
myself with a favourite actor—but as a mere human being I throw
myself on your mercy, and ask, in common charity, would you have
had me leave my warm bed, to shiver in a printer’s damp sheets, at
the risk of my reputation perhaps, and for the mere amusement of
some half hour, or more probably for no amusement at all—simply
because I was “down in the Bill?”
But there is no such Butcher, or Butcheress, or little Butcherling,
amongst you; and by your good leave and patience, the instalment
of my Reminiscences that is over due, shall be paid with interest in
the NEXT NUMBER.
THE TOP OF HIS PROFESSION.

SONNET TO A DECAYED SEAMAN.


HAIL! seventy-four cut down! Hail, Top and Lop!
Unless I’m much mistaken in my notion,
Thou wast a stirring Tar, before that hop
Became so fatal to thy locomotion;—
Now, thrown on shore, like a mere weed of ocean,
Thou readest still to men a lesson good,
To King and Country showing thy devotion,
By kneeling thus upon a stump of wood!
Still is thy spirit strong as alcohol;
Spite of that limb, begot of acorn-egg,—
Methinks,—thou Naval History in one Vol.—
A virtue shines, e’en in that timber leg,
For unlike others that desert their Poll,
Thou walkest ever with thy “Constant Peg!”
THE GREAT CONFLAGRATION.
Dreadful Fire—Destruction of both Houses of Parliament—The
Speaker’s House gutted—Reports of Incendiarism.

IT is our unexpected lot to announce that the Houses of Lords


and Commons, so often threatened with combustion, are in a state
of actual ignition. At this moment, both fabrics are furiously burning.
We are writing this paragraph without the aid of lamp or candles; by
the mere reflection of the flames. Nothing is known of the origin of
the fire, although it is throwing a light upon everything else.—
Evening Star.
The devouring element which destroyed Covent Garden and
Drury Lane, the Royalty and the Pantheon, has made its appearance
on a new stage, equally devoted to declamatory elocution. St.
Stephen’s Chapel is in flames! The floor which was trodden by the
eloquent legs of a Fox, a Burke, a Pitt, and a Sheridan, is reduced to
a heap of ashes; and the benches which sustained the Demosthenic
weight of a Wyndham, a Whitbread, and a Wilberforce, are a mere
mass of charcoal. The very roof that re-echoed the classicalities of
Canning is nodding to its fall. In Parliamentary language, Fire is in
possession of the House: the Destructive spirit is on its legs, and the
Conservative principle can offer but a feeble opposition.—Daily Post.
The blow is struck. What we have long foreseen has come to
pass. Incendiarism triumphs! The whole British Empire, as
represented by the three estates, is in a blaze! The Throne, the
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.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like