Reface: About This Text
Reface: About This Text
Reface: About This Text
/Volumes/201/MHDQ081/mhbra3%0/bra3fm
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 interface 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 associated with programming. With very little effort, the programmer can design
a screen that holds standard elements such as buttons, check boxes, radio buttons, text boxes, and list boxes. Each of these objects operates as expected,
producing a standard Windows or Web user interface.
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 programming 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 Chapter 1 and is used consistently in every chapter of the book.
The code for all in-chapter projects is available to instructors.
v
/Volumes/201/MHDQ081/mhbra3%0/bra3fm
TEXT FEATURES
/Volumes/201/MHDQ081/mhbra3%0/bra3ch02
Object-Oriented Concepts
are presented to offer students a better understanding of meeting user needs and employing
industry standards.
/Volumes/201/MHDQ081/mhbra3%0/bra3ch01
try
{
C Convert
H
A input
P
T values
E
R to numeric and
//
quantityInteger = int.Parse(quantityTex
try
{
priceDecimal = decimal.Parse(priceT
// Calculate values.
extendedPriceDecimal = quantityInte
discountDecimal = Decimal.Round(
bra17216_ch02_067-106.indd Page 77 7/21/08 8:02:47 PM user-s172
(extendedPriceDecimal * DISCOUNT
amountDueDecimal = extendedPriceDec
totalAmountDecimal += amountDueDeci
numberTransactionsInteger++;
// Format and display answers.
extendedPriceTextBox.Text = extende
Introduction to
Programming and
Visual C# 2008
1. Always test the tab order on your forms. Fix it if necessary by changing
the TabIndex properties of the controls.
2. Provide visual separation for input fields and output fields and always
make it clear to the user which are which.
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.
6. You can use the Checked property of a check box to set other properties
/Volumes/201/MHDQ081/mhbra3%0/bra3ch02
that must be true or false.
Tips
in the margins help students avoid potential
trouble spots in their programs and encourage
them to develop good programming habits.
TIP
Feedback Questions
give the students time to reflect on the
current topic and to evaluate their
understanding of the details.
Feedback 2.1
Hands-On Programming
Examples
guide students through the process of planning,
writing, and executing C# programs.
Create a picture box control that displays an enlarged icon and appears in a 3D
box. Make up a name that conforms to this textbooks naming conventions.
Property
In this project, Look Sharp Fitness Center needs to expand the clothing sale
project done previously in this chapter. In addition to calculating individual
sales and discounts, management wants to know the total amount of sales and
the number of transactions.
Add exception handling to the program so that missing or nonnumeric data
will not cause a run-time error.
Help the user by adding ToolTips wherever you think they will be useful.
Name
BorderStyle
SizeMode
Visible
Setting
/Volumes/201/MHDQ081/mhbra3%0/bra3
/Volumes/201-1/MHDQ081/mhbra3%0/bra3ch10
Programming Exercises
/Users/user-s208/Desktop/TEMPWORK/August 08/18:8:2008
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
enter the beginning inventory, the ending inventory, and the cost of goods
sold.
Form: Include labeled text boxes for the beginning inventory, the ending
inventory, and the cost of goods sold. After calculating the answers, display the average inventory and the turnover formatted in text boxes.
Case Studies
/Volumes/201/MHDQ081/mhbra3%0/bra3ch03
Case Studies
Custom Supplies Mail Order
The company has instituted a bonus program to give
its employees an incentive to sell more. For every dollar the store makes in a four-week period, the employees receive 2 percent of sales. The amount of bonus
each employee receives is based on the percentage of
hours he or she worked during the bonus period (a total of 160 hours).
h
ll ll
h
h
Learning Objectives
tell students what will be covered in the chapter
and what they will be able to do after completing
the chapter.
viii
/Volumes/201/MHDQ081/mhbra3%0/bra3fm
/Volumes/201/MHDQ081/mhbra3%0/bra3fm
ix
/Volumes/201/MHDQ081/mhbra3%0/bra3fm
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 thorough 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
/Volumes/201/MHDQ081/mhbra3%0/bra3fm
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 language 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 Developer from msdn.microsoft.com/express. Using these two products, you can
complete most of the exercises in this text.
xi
/Volumes/201/MHDQ081/mhbra3%0/bra3fm
/Volumes/201/MHDQ081/mhbra3%0/bra3fm
Anita Millspaugh teaches programming courses in Visual Basic, C#, and Java at
Mt. San Antonio College and has served as chair of the department for eight years.
She received her MBA from California State Polytechnic University, with a bachelors degree in Computer Information Systems. She has taught faculty at the National Computer Educators Institute and also has led Great Teachers Conferences
for Mt. SAC and for California Vocational Faculty.
xiii