HelpFeedback
Programming in Visual C# 2005
Information Center
Table of Contents
Feature Summary
Book Preface
Sample Chapter
About the Authors
PageOut


Student Edition
Instructor Edition
Programming in Visual C# 2005, 2/e

Julia Case Bradley, Mt. San Antonio College
Anita C. Millspaugh, Mt. San Antonio College

ISBN: 0073517186
Copyright year: 2008

Book Preface



Visual C# (C Sharp) is a relatively new language introduced by Microsoft along with Visual Studio .NET. Their 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.

 

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 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.

 

Changes in This Edition

This new update to the C# language includes significant changes, including greatly simplified database programming and Web development. The text includes many of the new features of .NET, including smart tags, the WebBrowser control, MenuStrips, ToolStrips, and the About Box template.

Output is displayed in read-only text boxes, which allows for easier cleanup procedures using the Clear method of the TextBox control.

All menus use the new MenuStrip component. Although the older-style menu is still available, it is destined to be eliminated from future product releases and is merely there for backward compatibility. The new controls offer much greater flexibility, including drop-down boxes in addition to buttons.

The student can create database applications by using drag-and-drop techniques with absolutely no code from the programmer. Even better, the applications can use the new DataGridView or include details in text boxes with a navigation bar. An example also shows how to use combo boxes to navigate through the records rather than using the navigation bar.

We have reorganized and expanded some sections of the text. Chapter 6 now covers multiple-form applications. The template for creating About forms is included. The chapter also demonstrates how to add a splash screen. Creating classes and using inheritance have been moved to Chapter 12. Students have the opportunity to learn more techniques, such as multiple forms in action, before creating multiple classes.

Visual Studio 2005 includes a new Web server that avoids the complications of using IIS for Web development. Students can create Web applications on their own storage devices (floppies, Zips, flash drives, hard drives). The projects can easily be copied and run on other machines.

Drag-and-drop is now covered in the graphics chapter (Chapter 13). Students learn the development techniques for this familiar operation. Students also learn to play sounds in an application using the SoundPlayer class.

Chapter 14 includes the new WebBrowser control, which makes it easy to incorporate Web content on a Windows form. Other new features included are ToolStrips, StatusStrips, and code snippets.

The narrative, step-by-step exercise, screen captures, and appendices have all been updated to C# 2005. The screen captures are based on Windows XP using the Professional Edition of Visual Studio.

 

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 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# 2005,” 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 guidelines 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.

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 conditions 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, “Programming with Web Forms,” 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.

Chapter 10, “Accessing Database Files,” introduces ADO.NET, which is Microsoft’s latest 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.

Chapter 11, “Saving Data in 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 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. Drag-and-drop events are used to transfer 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 the new ToolStrip and StatusStrip controls, and add Web content to a Windows form using the WebBrowser control. The new code-snippet feature is introduced.

The Appendices 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 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, including Janna Martin, Linda Schreiber, Kristen Bradley, Alaina Grayson, and so many more.

We greatly appreciate Robert Price and Theresa Berry for their thorough technical reviews, constructive criticism, and many valuable suggestions. And, most importantly, we are grateful to Dennis, Richard, Tricia, Scott, Eric, and Kenna for their support and understanding through the long days and busy phone lines.

We want to thank our reviewers, who have made many helpful suggestions: Sue Fitzgerald, Ph.D., Metropolitan State University ; Terry Foty, Portland Community College ; Stephen Gilbert, Orange Coast College ; Gregory Kuhlmann, The University of Texas at Austin ; Sebnem Onsay, Oakland University ; Von Roderick Plessner, Northwest State Community College ; Martin Schray, DePaul University ; Gene Snare, Southwestern Illinois College ; and Christopher C. Whitehead, Columbus State University .

 

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

 


To obtain an instructor login for this Online Learning Center, ask your local sales representative. If you're an instructor thinking about adopting this textbook, request a free copy for review.