Sams Teach Yourself Visual C# 2008 in 24 Hours: Complete Starter Kit

Book description

Sams Teach Yourself Visual C#® 2008 in 24 Hours

James Foxall

Starter Kit

DVD includes Visual C#® 2008 Express Edition

In just 24 sessions of one hour or less, you will be up and running with Visual C# 2008. Using a straightforward, step-by-step approach, each lesson builds upon the previous one, allowing you to learn the essentials of Visual C# from the ground up.

By the Way notes present interesting pieces of information.

Did You Know? tips offer advice or teach an easier way to do something.

Watch Out! cautions advise you about potential problems and help you steer clear of disaster.

Learn how to...

  • Use the powerful design environment of Visual Studio 2008

  • Design a feature-rich interface using components such as tree views and tabs

  • Create robust applications using modern error handling

  • Draw fast graphics using GDI+

  • Build a database application using ADO.NET

  • Distribute a Visual C# 2008 application

  • James Foxall is vice president of Tigerpaw Software, Inc. (www.tigerpawsoftware.com), a Bellevue, Nebraska, Microsoft Certified Partner specializing in commercial database applications. He manages the development, support, training, and education of Tigerpaw CRM+, an award-winning application that automates contact management, marketing, service and repair, proposal generation, inventory control, and purchasing. Tigerpaw has more than 20,000 licensed users in 27 countries. Foxall’s experience in creating certified Office-compatible software has made him an authority on application interface and behavior standards. In addition to being a well-known author, James is an international speaker on Microsoft technologies, has taught at the college level, and contributes to several journals.

    DVD Includes:

  • Microsoft® Visual C#® 2008 Express Edition

  • On the Web:

  • Register your book at informit.com/title/9780672329906 for access to author code, examples, updates and corrections as they become available.

  • Category: Microsoft Programming

    Covers: Visual C# 2008

    User Level: Beginning

    Table of contents

    1. Copyright
      1. Dedication
    2. About the Author
    3. Acknowledgments
    4. We Want to Hear from You!
    5. Reader Services
    6. Introduction
      1. Audience and Organization
      2. Conventions Used in This Book
      3. Onward and Upward!
    7. I. The Visual C# 2008 Environment
      1. 1. Jumping In with Both Feet: A Visual C# 2008 Programming Tour
        1. Starting Visual C# 2008
        2. Creating a New Project
        3. Understanding the Visual Studio .NET Environment
        4. Changing the Characteristics of Objects
          1. Naming Objects
          2. Setting the Text Property of the Form
          3. Saving a Project
          4. Giving the Form an Icon
          5. Changing the Size of the Form
        5. Adding Controls to a Form
        6. Designing an Interface
          1. Adding a Visible Control to a Form
          2. Adding an Invisible Control to a Form
        7. Writing the Code Behind an Interface
          1. Letting a User Browse for a File
          2. Terminating a Program Using Code
        8. Running a Project
        9. Summary
        10. Q&A
        11. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      2. 2. Navigating Visual C# 2008
        1. Using the Visual C# 2008 Start Page
          1. Creating New Projects
          2. Opening an Existing Project
        2. Navigating and Customizing the Visual C# Environment
          1. Working with Design Windows
            1. Showing and Hiding Design Windows
            2. Floating Design Windows
            3. Docking Design Windows
            4. Auto-Hiding Design Windows
        3. Working with Toolbars
          1. Showing and Hiding Toolbars
          2. Docking and Resizing Toolbars
        4. Adding Controls to a Form Using the Toolbox
        5. Setting Object Properties Using the Properties Window
          1. Selecting an Object and Viewing Its Properties
          2. Viewing and Changing Properties
          3. Working with Color Properties
          4. Viewing Property Descriptions
        6. Managing Projects
          1. Managing Project Files with the Solution Explorer
          2. Working with Solutions
          3. Understanding Project Components
          4. Setting Project Properties
          5. Adding and Removing Project Files
        7. A Quick-and-Dirty Programming Primer
          1. Storing Values in Variables
          2. Using Procedures to Write Functional Units of Code
            1. MessageBox.Show()
        8. Getting Help
        9. Summary
        10. Q&A
        11. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      3. 3. Understanding Objects and Collections
        1. Understanding Objects
        2. Understanding Properties
          1. Getting and Setting Properties
          2. Working with an Object and Its Properties
        3. Understanding Methods
          1. Triggering Methods
          2. Understanding Method Dynamism
        4. Building a Simple Object Example Project
          1. Creating the Interface for the Drawing Project
          2. Writing the Object-Based Code
          3. Testing Your Object Example Project
        5. Understanding Collections
        6. Using the Object Browser
        7. Summary
        8. Q&A
        9. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      4. 4. Understanding Events
        1. Understanding Event-Driven Programming
          1. Triggering Events
          2. Events Triggered Through User Interaction
            1. Events Triggered by an Object
            2. Events Triggered by the Operating System
          3. Avoiding Recursive Events
          4. Accessing an Object’s Events
          5. Working with Event Parameters
          6. Deleting an Event Handler
        2. Building an Event Example Project
          1. Creating the User Interface
          2. Creating Event Handlers
        3. Summary
        4. Q&A
        5. Workshop
          1. Quiz
          2. Answers
          3. Exercises
    8. II. Building a User Interface
      1. 5. Building Forms—The Basics
        1. Changing a Form’s Name
        2. Changing a Form’s Appearance
          1. Displaying Text on a Form’s Title Bar
          2. Changing a Form’s Background Color
          3. Adding an Image to a Form’s Background
          4. Giving a Form an Icon
          5. Adding Minimize, Maximize, and Control Box Buttons to a Form
          6. Changing the Appearance and Behavior of a Form’s Border
          7. Controlling the Minimum and Maximum Size of a Form
        3. Showing and Hiding Forms
          1. Showing Forms
          2. Understanding Form Modality
          3. Specifying the Initial Display Position of a Form
          4. Displaying a Form in a Normal, Maximized, or Minimized State
          5. Preventing a Form from Appearing in the Taskbar
          6. Unloading Forms
        4. Summary
        5. Q&A
        6. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      2. 6. Building Forms—Advanced Techniques
        1. Working with Controls
          1. Adding Controls to a Form
        2. Adding a Control by Double-Clicking It in the Toolbox
        3. Adding a Control by Dragging from the Toolbox
        4. Adding a Control by Drawing It
          1. Manipulating Controls
            1. Using the Grid (Size and Snap)
            2. Using Snap Lines
            3. Selecting a Group of Controls
            4. Aligning Controls
            5. Making Controls the Same Size
            6. Evenly Spacing a Group of Controls
            7. Setting Property Values for a Group of Controls
            8. Anchoring and Autosizing Controls
          2. Creating a Tab Order
          3. Layering Controls (Z-Order)
        5. Creating Topmost Nonmodal Windows
        6. Creating Transparent Forms
        7. Creating Scrollable Forms
        8. Creating MDI Forms
        9. Summary
        10. Q&A
        11. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      3. 7. Working with Traditional Controls
        1. Displaying Static Text with the Label Control
        2. Allowing Users to Enter Text Using a Text Box
          1. Specifying Text Alignment
          2. Creating a Multiline Text Box
          3. Adding Scrollbars
          4. Limiting the Number of Characters a User Can Enter
          5. Creating Password Fields
          6. Understanding the Text Box’s Common Events
        3. Creating Buttons
          1. Accept and Cancel Buttons
        4. Presenting Yes/No Options Using Check Boxes
        5. Creating Containers and Groups of Option Buttons
          1. Using Panels and Group Boxes
          2. Working with Radio Buttons
        6. Displaying a List with the List Box
          1. Manipulating Items at Design Time
          2. Manipulating Items at Runtime
            1. Adding Items to a List
            2. Removing Items from a List
            3. Clearing a List
            4. Retrieving Information About the Selected Item in a List
          3. Sorting a List
        7. Creating Drop-Down Lists Using the Combo Box
        8. Summary
        9. Q&A
        10. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      4. 8. Using Advanced Controls
        1. Creating Timers
        2. Creating Tabbed Dialog Boxes
        3. Storing Pictures in an Image List
        4. Building Enhanced Lists Using the List View
          1. Creating Columns
          2. Adding List Items
          3. Manipulating a List View Using Code
            1. Adding List Items Using Code
            2. Determining the Selected Item in Code
            3. Removing List Items Using Code
            4. Removing All List Items
        5. Creating Hierarchical Lists with the Tree View
          1. Adding Nodes to a Tree View
          2. Removing Nodes
          3. Clearing All Nodes
        6. Summary
        7. Q&A
        8. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      5. 9. Adding Menus and Toolbars to Forms
        1. Building Menus
          1. Creating Top-Level Menu Items
          2. Creating Menu Items for a Top-Level Menu
          3. Moving and Deleting Menu Items
          4. Creating Checked Menu Items
          5. Programming Menus
          6. Implementing Context Menus
          7. Assigning Shortcut Keys to Menu Items
        2. Using the Toolbar Control
          1. Adding Toolbar Buttons Using the Buttons Collection
          2. Programming Toolbars
          3. Creating Drop-Down Menus for Toolbar Buttons
        3. Creating a Status Bar
        4. Summary
        5. Q&A
        6. Workshop
          1. Quiz
          2. Answers
          3. Exercises
    9. III. Making Things Happen: Programming
      1. 10. Creating and Calling Methods
        1. Understanding Class Members
        2. Defining and Writing Methods
          1. Declaring Methods That Don’t Return Values
          2. Declaring Procedures That Return Values
        3. Calling Methods
          1. Passing Parameters
        4. Exiting Methods
        5. Creating Static Methods
        6. Avoiding Infinite Recursion
        7. Summary
        8. Q&A
        9. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      2. 11. Using Constants, Data Types, Variables, and Arrays
        1. Understanding Data Types
          1. Determining Data Type
          2. Casting Data from One Data Type to Another
        2. Defining and Using Constants
        3. Declaring and Referencing Variables
          1. Declaring Variables
          2. Passing Literal Values to a Variable
          3. Using Variables in Expressions
        4. Working with Arrays
          1. Declaring Arrays
          2. Referencing Array Variables
          3. Creating Multidimensional Arrays
        5. Determining Scope
          1. Understanding Block Scope
          2. Understanding Method-Level (Local) Scope
          3. Understanding Private-Level Scope
        6. Naming Conventions
          1. Using Prefixes to Denote Data Type
          2. Denoting Scope Using Variable Prefixes
        7. Using Variables in Your Picture Viewer Project
          1. Creating the Variables for the Options
          2. Initializing and Using the Options Variables
        8. Summary
        9. Q&A
        10. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      3. 12. Performing Arithmetic, String Manipulation, and Date/Time Adjustments
        1. Performing Basic Arithmetic Operations with Visual C#
          1. Performing Addition
          2. Performing Subtraction and Negation
          3. Performing Multiplication
          4. Performing Division
          5. Performing Modulus Arithmetic
          6. Determining the Order of Operator Precedence
        2. Comparing Equalities
        3. Understanding Boolean Logic
          1. Using the And (&) Operator
          2. Using the Not (!) Operator
          3. Using the Or (|) Operator
          4. Using the Xor (^) Operator
          5. Manipulating Strings
          6. Concatenating Strings of Text
          7. Using the Basic String Methods and Properties
            1. Determining the Number of Characters Using Length
            2. Retrieving Text from a String Using the Substring() Method
            3. Determining Whether One String Contains Another Using the IndexOf() Method
            4. Trimming Beginning and Trailing Spaces from a String
            5. Replacing Text Within a String
        4. Working with Dates and Times
          1. Understanding the DateTime Data Type
          2. Adding to or Subtracting from a Date or Time
          3. Retrieving Parts of a Date
          4. Formatting Dates and Times
          5. Retrieving the Current System Date and Time
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      4. 13. Making Decisions in Visual C# Code
        1. Making Decisions Using if...else
          1. Executing Code When expression Is false
          2. Nesting if...else Constructs
        2. Evaluating an Expression for Multiple Values Using switch
          1. Building a switch Example
        3. Summary
        4. Q&A
        5. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      5. 14. Looping for Efficiency
        1. Looping a Specific Number of Times Using for
          1. Initiating the Loop Using for
          2. Creating a for Example
        2. Using while and do...while to Loop an Indeterminate Number of Times
          1. Creating a do...while
          2. Ending a do...while Loop
          3. Creating a do...while Example
        3. Summary
        4. Q&A
        5. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      6. 15. Debugging Your Code
        1. Adding Comments to Your Code
        2. Identifying the Two Basic Types of Errors
        3. Using Visual C# Debugging Tools
          1. Working with Break Points
          2. Using the Immediate Window
          3. Using the Output Window
        4. Writing an Error Handler Using Try...Catch...Finally
          1. Dealing with an Exception
          2. Handling an Anticipated Exception
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      7. 16. Designing Objects Using Classes
        1. Understanding Classes
          1. Encapsulating Data and Code Using Classes
          2. Comparing Instance Members with Static Members
          3. Understanding Constructors and Destructors
          4. Creating an Object Interface
            1. Exposing Object Attributes as Properties
              1. Creating Readable Properties Using the get Construct
              2. Creating Writable Properties Using the set Construct
              3. Creating Read-Only or Write-Only Properties
            2. Exposing Functions as Methods
        2. Instantiating Objects from Classes
          1. Binding an Object Reference to a Variable
            1. Late Binding an Object Variable
            2. Early Binding an Object Variable
            3. Creating a New Object When Dimensioning a Variable
          2. Releasing Object References
          3. Understanding the Lifetime of an Object
        3. Summary
        4. Q&A
        5. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      8. 17. Interacting with Users
        1. Displaying Messages Using the MessageBox.Show() Function
          1. Specifying Buttons and an Icon
          2. Determining Which Button Is Clicked
          3. Creating Good Messages
        2. Creating Custom Dialog Boxes
        3. Interacting with the Keyboard
        4. Using the Common Mouse Events
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      9. 18. Working with Graphics
        1. Understanding the Graphics Object
          1. Creating a Graphics Object for a Form or Control
          2. Creating a Graphics Object for a New Bitmap
          3. Disposing of an Object When It Is No Longer Needed
        2. Working with Pens
        3. Using System Colors
        4. Working with Rectangles
        5. Drawing Shapes
          1. Drawing Lines
          2. Drawing Rectangles
          3. Drawing Circles and Ellipses
          4. Clearing a Drawing Surface
        6. Drawing Text
        7. Persisting Graphics on a Form
        8. Building a Graphics Project Example
        9. Summary
        10. Q&A
        11. Workshop
          1. Quiz
          2. Answers
          3. Exercises
    10. IV. Working with Data
      1. 19. Performing File Operations
        1. Using the OpenFileDialog and SaveFileDialog Controls
          1. Using the OpenFileDialog Control
            1. Creating File Filters
            2. Showing the Open File Dialog Box
          2. Using the SaveFileDialog Control
        2. Manipulating Files with the File Object
          1. Determining Whether a File Exists
          2. Copying a File
          3. Moving a File
          4. Renaming a File
          5. Deleting a File
          6. Retrieving a File’s Properties
            1. Getting Date and Time Information About a File
            2. Getting the Attributes of a File
            3. Writing Code to Retrieve a File’s Properties
        3. Manipulating Directories with the Directory Object
        4. Summary
        5. Q&A
        6. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      2. 20. Working with Text Files and the Registry
        1. Working with the Registry
          1. Understanding the Structure of the Windows Registry
          2. Accessing the Registry with Registry and RegistryKey
            1. Creating Registry Keys
            2. Deleting Registry Keys
            3. Getting and Setting Key Values
          3. Modifying Your Picture Viewer Project to Use the Registry
            1. Displaying Options from the Registry
            2. Saving Options to the Registry
            3. Using the Options Stored in the Registry
            4. Testing and Debugging Your Picture Viewer Project
        2. Reading and Writing Text Files
          1. Writing to a Text File
          2. Reading a Text File
          3. Modifying Your Picture Viewer Project to Use a Text File
            1. Creating the Picture Viewer Log File
            2. Displaying the Picture Viewer Log File
            3. Testing Your Picture Viewer Log
        3. Summary
        4. Q&A
        5. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      3. 21. Working with a Database
        1. Introducing ADO.NET
          1. Connecting to a Database
          2. Closing a Connection to a Data Source
        2. Manipulating Data
          1. Understanding DataTable Objects
          2. Creating a DataAdapter
          3. Creating and Populating DataTable Objects
          4. Referencing Fields in a DataRow
          5. Navigating Records
          6. Editing Records
          7. Creating New Records
          8. Deleting Records
          9. Running the Database Example
        3. Summary
        4. Q&A
        5. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      4. 22. Controlling Other Applications Using Automation
        1. Creating a Reference to an Automation Library
        2. Creating an Instance of an Automation Server
        3. Manipulating the Server
          1. Forcing Excel to Show Itself
          2. Creating an Excel Workbook
          3. Working with Data in an Excel Workbook
          4. Testing Your Client Application
        4. Automating Microsoft Word
          1. Creating a Reference to an Automation Library
          2. Creating an Instance of an Automation Server
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
          3. Exercises
    11. V. Developing Solutions and Beyond
      1. 23. Deploying Applications
        1. Understanding ClickOnce Technology
        2. Using the Publish Wizard to Create a ClickOnce Application
        3. Testing Your Picture Viewer ClickOnce Install Program
        4. Uninstalling an Application You’ve Distributed
        5. Setting Advanced Options for Creating ClickOnce Programs
        6. Summary
        7. Q&A
        8. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      2. 24. The 10,000-Foot View
        1. The .NET Framework
        2. Common Language Runtime
        3. Microsoft Intermediate Language
        4. Namespaces
        5. Common Type System
        6. Garbage Collection
        7. Further Reading
        8. Summary

    Product information

    • Title: Sams Teach Yourself Visual C# 2008 in 24 Hours: Complete Starter Kit
    • Author(s):
    • Release date: June 2008
    • Publisher(s): Sams
    • ISBN: 9780768678802