You are previewing Programming Microsoft® Windows® with C#.
O'Reilly logo
Programming Microsoft® Windows® with C#

Book Description

“Look it up in Petzold” remains the last word on Windows development. In this.NET-ready Windows programming guide, the best-selling author shows you how to get the most out of Windows Forms—the next-generation Windows programming class library.

Table of Contents

  1. Programming Microsoft Windows with C#
    1. SPECIAL OFFER: Upgrade this ebook with O’Reilly
    2. A Note Regarding Supplemental Files
    3. Introduction
      1. Windows Programming: An Overview
      2. User Requirements
      3. System Requirements
      4. The Organization of This Book
      5. The CD-ROM
      6. Support
      7. Special Thanks
    4. 1. Console Thyself
      1. The C# Version
      2. Anatomy of a Program
      3. C# Namespaces
      4. Console I/O
      5. C# Data Types
      6. Expressions and Operators
      7. Conditions and Iterations
      8. The Leap to Objects
      9. Programming in the Key of C#
      10. Static Methods
      11. Exception Handling
      12. Throwing Exceptions
      13. Getting and Setting Properties
      14. Constructors
      15. Instances and Inheritance
      16. A Bigger Picture
      17. Naming Conventions
      18. Beyond the Console
    5. 2. Hello, Windows Forms
      1. The Message Box
      2. The Form
      3. Showing the Form
      4. It's an Application and We Want to Run It
      5. Variations on a Theme
      6. Form Properties
      7. Event-Driven Input
      8. Handling the Paint Event
      9. Displaying Text
        1. The Font
        2. The Brush
        3. The Coordinate Points
      10. The Paint Event Is Special!
      11. Multiple Forms, Multiple Handlers
      12. Inheriting Forms
      13. The OnPaint Method
      14. Does Main Belong Here?
      15. Events and "On" Methods
    6. 3. Essential Structures
      1. Classes and Structures
      2. Two-Dimensional Coordinate Points
      3. Arrays of Points
      4. The Size Structure
      5. The Float Versions
      6. A Rectangle Is a Point and a Size
      7. Rectangle Properties and Methods
      8. A Nice-Sized Form
      9. The Form and the Client
      10. Point Conversions
      11. The Color Structure
      12. The 141 Color Names
      13. Pens and Brushes
      14. System Colors
      15. The Known Colors
      16. What to Use?
      17. Getting a Feel for Repaints
      18. Centering Hello World
      19. Measuring the String
      20. Text in a Rectangle
    7. 4. An Exercise in Text Output
      1. System Information
      2. Spacing Lines of Text
      3. Property Values
      4. Formatting into Columns
      5. Everything Is an Object
      6. Listing the System Information
      7. Windows Forms and Scroll Bars
      8. Scrolling a Panel Control
      9. The Heritage of ScrollableControl
      10. Scrolling Without Controls
      11. Actual Numbers
      12. Keeping It Green
      13. Don't Be a Pig
      14. Reflecting on the Future
    8. 5. Lines, Curves, and Area Fills
      1. How to Get a Graphics Object
      2. Pens, Briefly
      3. Straight Lines
      4. An Introduction to Printing
      5. Properties and State
      6. Anti-Aliasing
      7. Multiple Connected Lines
      8. Curves and Parametric Equations
      9. The Ubiquitous Rectangle
      10. Generalized Polygons
      11. Easier Ellipses
      12. Arcs and Pies
      13. Filling Rectangles, Ellipses, and Pies
      14. Off by 1
      15. Polygons and the Filling Mode
    9. 6. Tapping into the Keyboard
      1. Ignoring the Keyboard
      2. Who's Got the Focus?
      3. Keys and Characters
      4. Keys Down and Keys Up
      5. The Keys Enumeration
      6. Testing the Modifier Keys
      7. Reality Check
      8. A Keyboard Interface for SysInfo
      9. KeyPress for Characters
      10. Control Characters
      11. Looking at the Keys
      12. Invoking the Win32 API
      13. Handling Input from Foreign Keyboards
      14. Input Focus
      15. The Missing Caret
      16. Echoing Key Characters
      17. Right-to-Left Problems
    10. 7. Pages and Transforms
      1. Device Independence Through Text
      2. How Much Is That in Real Money?
      3. Dots Per Inch
      4. What's with the Printer?
      5. Manual Conversions
      6. Page Units and Page Scale
      7. Pen Widths
      8. Page Transforms
      9. Saving the Graphics State
      10. Metrical Dimensions
      11. Arbitrary Coordinates
      12. What You Can't Do
      13. Hello, World Transform
      14. The Big Picture
      15. Linear Transforms
      16. Introducing Matrixes
      17. The Matrix Class
      18. Shear and Shear Alike
      19. Combining Transforms
    11. 8. Taming the Mouse
      1. The Dark Side of the Mouse
      2. Ignoring the Mouse
      3. Some Quick Definitions
      4. Information About the Mouse
      5. The Mouse Wheel
      6. The Four Basic Mouse Events
      7. Doing the Wheel
      8. Mouse Movement
      9. Tracking and Capturing the Mouse
      10. Adventures in Tracking
      11. Generalizing Code with Interfaces
      12. Clicks and Double-Clicks
      13. Mouse-Related Properties
      14. Entering, Leaving, Hovering
      15. The Mouse Cursor
      16. An Exercise in Hit-Testing
      17. Adding a Keyboard Interface
      18. Putting the Children to Work
      19. Hit-Testing Text
      20. Scribbling with the Mouse
    12. 9. Text and Fonts
      1. Fonts Under Windows
      2. Talking Type
      3. Font Heights and Line Spacing
      4. Default Fonts
      5. Variation on a Font
      6. Creating Fonts by Name
      7. A Point Size by Any Other Name…
      8. Clash of the Units
      9. Font Properties and Methods
      10. New Fonts from FontFamily
      11. Understanding the Design Metrics
      12. Arrays of Font Families
      13. Font Collections
      14. Variations on DrawString
      15. Anti-Aliased Text
      16. Measuring the String
      17. The StringFormat Options
      18. Grid Fitting and Text Fitting
      19. Horizontal and Vertical Alignment
      20. The Hotkey Display
      21. A Clip and a Trim
      22. Start a Tab
    13. 10. The Timer and Time
      1. The Timer Class
      2. The DateTime Structure
      3. Local Time and Universal Time
      4. The Tick Count
      5. Calendars Around the World
      6. A Readable Rendition
      7. A Simple Culture-Specific Clock
      8. The Retro Look
      9. An Analog Clock
      10. A Little Puzzle Called Jeu de Taquin
    14. 11. Images and Bitmaps
      1. Bitmap Support Overview
      2. Bitmap File Formats
      3. Loading and Drawing
      4. Image Information
      5. Rendering the Image
      6. Fitting to a Rectangle
      7. Rotate and Shear
      8. Displaying Part of the Image
      9. Drawing on the Image
      10. More on the Image Class
      11. The Bitmap Class
      12. Hello World with a Bitmap
      13. The Shadow Bitmap
      14. Binary Resources
      15. Animation
      16. The Image List
      17. The Picture Box
    15. 12. Buttons and Labels and Scrolls (Oh My!)
      1. Buttons and Clicks
      2. Keyboard and Mouse
      3. Control Issues
      4. Deeper into Buttons
      5. Appearance and Alignment
      6. Buttons with Bitmaps
      7. Multiple Handlers or One?
      8. Drawing Your Own Buttons
      9. Dropping Anchor
      10. Dock Around the Clock
      11. Children of the Form
      12. Z-Order
      13. The Check Box
      14. The Three-State Alternative
      15. The Label Control
      16. Tab Stops and Tab Order
      17. Identifying the Controls
      18. The Auto-Scale Option
        1. How the Windows Forms Designer Uses Auto-Scale
        2. Creative AutoScaleBaseSize Settings
        3. Inside Auto-Scale
      19. A Hexadecimal Calculator
      20. Radio Buttons and Group Boxes
      21. Scroll Bars
      22. The Track Bar Alternative
    16. 13. Béziers and Other Splines
      1. The Bézier Spline in Practice
      2. A More Stylish Clock
      3. Collinear Béziers
      4. Circles and Arcs with Béziers
      5. Bézier Art
      6. The Mathematical Derivation
      7. The Canonical Spline
      8. Canonical Curve Derivation
    17. 14. Menus
      1. Menus and Menu Items
      2. Menu Shortcut Keys
      3. Your First Menu
      4. Unconventional Menus
      5. MenuItem Properties and Events
      6. Checking the Items
      7. Working with Context Menus
      8. The Menu Item Collection
      9. The Standard Menu (A Proposal)
      10. The Owner-Draw Option
    18. 15. Paths, Regions, and Clipping
      1. A Problem and Its Solution
      2. The Path, More Formally
      3. Creating the Path
      4. Rendering the Path
      5. Path Transforms
      6. Other Path Modifications
      7. Clipping with Paths
      8. Clipping Bitmaps
      9. Regions and Clipping
    19. 16. Dialog Boxes
      1. Your First Modal Dialog Box
      2. Modal Dialog Box Termination
      3. Accept and Cancel
      4. Screen Location
      5. The About Box
      6. Defining Properties in Dialog Boxes
      7. Implementing an Apply Button
      8. The Modeless Dialog Box
      9. The Common Dialog Boxes
      10. Choosing Fonts and Colors
      11. Using the Windows Registry
      12. The Open File Dialog Box
      13. The Save File Dialog Box
    20. 17. Brushes and Pens
      1. Filling in Solid Colors
      2. Hatch Brushes
      3. The Rendering Origin
      4. Texture Brushes
      5. Linear Gradient Brushes
      6. Path Gradient Brushes
      7. Tiling the Brush
      8. Pens Can Be Brushes Too
      9. A Dash of Style
      10. Caps and Joins
    21. 18. Edit, List, and Spin
      1. Single-Line Text Boxes
      2. Multiline Text Boxes
      3. Cloning Notepad
      4. The Notepad Clone with File I/O
      5. Notepad Clone Continued
      6. Special-Purpose Text Boxes
      7. The Rich Text Box
      8. ToolTips
      9. The List Box
      10. List Box + Text Box = Combo Box
      11. Up-Down Controls
    22. 19. Font Fun
      1. Getting Started
      2. Brushed Text
      3. Font Transforms
      4. Text and Paths
      5. Nonlinear Transforms
    23. 20. Toolbars and Status Bars
      1. The Basic Status Bar
      2. The Status Bar and Auto-Scroll
      3. Status Bar Panels
      4. StatusBarPanel Properties
      5. Menu Help
      6. The Basic Toolbar
      7. Toolbar Variations
      8. Toolbar Events
      9. Toolbar Styles
    24. 21. Printing
      1. Printers and Their Settings
      2. Page Settings
      3. Defining a Document
      4. Handling PrintDocument Events
      5. The Page Dimensions
      6. The Print Controller
      7. Using the Standard Print Dialog Box
      8. Setting Up the Page
      9. Print Preview
    25. 22. Tree View and List View
      1. Splitsville
      2. Tree Views and Tree Nodes
      3. Images in Tree Views
      4. Tree View Events
      5. Node Navigation
      6. The Directory Tree
      7. Displaying Images
      8. List View Basics
      9. List View Events
    26. 23. Metafiles
      1. Loading and Rendering Existing Metafiles
      2. Metafile Sizes and Rendering
      3. Converting Metafiles to Bitmaps
      4. Creating New Metafiles
      5. The Metafile Boundary Rectangle
      6. Metafiles and the Page Transform
      7. The Metafile Type
      8. Enumerating the Metafile
    27. 24. Clip, Drag, and Drop
      1. Items and Formats
      2. The Tiny (But Powerful) Clipboard Class
      3. Getting Objects from the Clipboard
      4. Clipboard Data Formats
      5. Clipboard Viewers
      6. Setting Multiple Clipboard Formats
      7. Drag and Drop
    28. A. Files and Streams
      1. The Most Essential File I/O Class
      2. FileStream Properties and Methods
      3. The Problem with FileStream
      4. Other Stream Classes
      5. Reading and Writing Text
      6. Binary File I/O
      7. The Environment Class
      8. File and Path Name Parsing
      9. Parallel Classes
      10. Working with Directories
      11. File Manipulation and Information
    29. B. Math Class
      1. Numeric Types
      2. Checking Integer Overflow
      3. The Decimal Type
      4. Floating-Point Infinity and NaNs
      5. The Math Class
      6. Floating-Point Remainders
      7. Powers and Logarithms
      8. Trigonometric Functions
    30. C. String Theory
      1. The char Type
      2. String Constructors and Properties
      3. Copying Strings
      4. Converting Strings
      5. Concatenating Strings
      6. Comparing Strings
      7. Searching the String
      8. Trimming and Padding
      9. String Manipulation
      10. Formatting Strings
      11. Array Sorting and Searching
      12. The StringBuilder Class
    31. Index
    32. SPECIAL OFFER: Upgrade this ebook with O’Reilly