You are previewing GDI+ Custom Controls with Visual C# 2005.
O'Reilly logo
GDI+ Custom Controls with Visual C# 2005

Book Description

If you want to build application custom controls with C# but you don't know where to start, or you are intimidated by the huge amount of information that needs to be absorbed, then this book is for you. This friendly tutorial is based on numerous examples with real-world applicability, and includes a case study featuring the development of a fully functional PieChart control.

Showing you how to use the free Visual C# 2005 Express Edition environment to develop your controls, GDI+ Custom Controls with Visual C# 2005 will teach you how to create professional, reusable custom controls for your desktop applications in no time.

This shows you how to:

Understand the basics of custom controls
Use GDI+ to draw your own controls
Implement double buffering to speed up your forms
Add printing functionality to your custom controls
Handle the mouse events to improve the user experience
Offer design-time support for programmers using your control
Design intuitive interfaces for your users

Throughout the book the emphasis is on using examples to illustrate concepts and techniques. Code is shown in detail, and explained thoroughly. The examples themselves are intended to be both intructional and useful in their own right.

This book has been written with the intermediate C# developer in mind. Assuming a working knowledge of C#, the book teaches you how to implement custom controls using Visual C# 2005 Express Edition and all other versions of Visual C#, and GDI+ with .NET 2.0. The book focused on application and not web custom controls.

Table of Contents

  1. GDI+ Custom Controls with Visual C# 2005
    1. GDI+ Custom Controls with Visual C# 2005
    2. Credits
    3. About the Authors
    4. About the Reviewer
    5. Preface
      1. What This Book Covers
      2. Conventions
      3. Reader Feedback
      4. Customer Support
        1. Downloading the Example Code for the Book
        2. Errata
        3. Questions
    6. 1. Introduction to Custom Controls
      1. What Are Controls?
      2. Introducing Custom Controls
        1. Categories of User Controls
      3. Preparing Your Environment
      4. What Are Custom Controls Made Of?
        1. Private Fields
        2. Properties
        3. Indexers
        4. Events and Delegates
          1. Handling Events
        5. Collections
        6. Enums
      5. Building TinyNoiseMaker
            1. Time for Action—Creating the TinyNoiseMaker Custom Control
              1. What Just Happened?
      6. Extending TinyNoiseMaker
            1. Time for Action—Adding Public Functionality
              1. What Just Happened?
            2. Time for Action—Using the Control’s Public Interface
              1. What Just Happened?
      7. Summary
    7. 2. Introduction to GDI+
      1. Understanding Control Drawing
        1. Understanding GDI+
        2. The Graphics Object
        3. The Control.Paint Event
        4. Invalidation
      2. Simple Drawing on a Form
            1. Time for Action—Creating the Application
              1. What Just Happened?
      3. Drawing Inside a Panel Object
            1. Time for Action—Creating the Application
              1. What Just Happened?
      4. Drawing Inside a Control
            1. Time for Action—Creating the Application
              1. What Just Happened?
      5. Summary
    8. 3. Basic Drawing
      1. The GDI+ Coordinate System
      2. Drawing with GDI+
        1. Using the Color Object
        2. Drawing Using the Pen Object
        3. Filling Surfaces Using the Brush Object
        4. Drawing Text Using the Font Object
        5. Improving Drawing Quality
      3. Building the GradientLabel Control
            1. Time for Action—Creating the GradientLabel Custom Control
              1. What Just Happened?
      4. Summary
    9. 4. Drawing Complex Shapes and Using Transformations
      1. Drawing Complex Shapes
        1. The GraphicsPath Object
        2. The Region Object
      2. Clipping Drawing Using Region Objects
        1. Keeping Drawing Inside a Region
        2. Keeping Drawing Outside a Region
      3. Graphics Transformations
        1. Translation
        2. Rotation
        3. Scaling
      4. Creating the Clock Control
            1. Time for Action—Creating the Clock Control
            2. Time for Action—Updating the Clock to Use Transformations
              1. What Just Happened?
      5. Summary
    10. 5. Drawing Control Parts, Borders, and Adornments
      1. Rendering Common Control Parts
        1. Drawing Buttons
        2. Drawing Caption Buttons
        3. Drawing Checkboxes
        4. Drawing Drop-Down Buttons
        5. Drawing Radio Buttons
        6. Drawing Scroll Buttons
      2. Rendering Borders and Frames
        1. Rendering Button Borders
        2. Rendering 3D Borders
      3. Rendering Control Adornments
      4. Creating Multiple Controls that Reuse the Same Functionality
        1. Creating a Base Class for Two or More Controls
            1. Time for Action—Creating the ControlPart Base Class
              1. What Just Happened?
        2. Creating Derived Controls
            1. Time for Action—Creating the ScrollArrowButton Control
              1. What Just Happened?
            2. Time for Action—Creating the CheckButton Control
              1. What Just Happened?
      5. Extending Existing Controls
            1. Time for Action—Creating the BorderGradientPanel Control
              1. What Just Happened?
            2. Time for Action—Implementing the GradientButton Control
              1. What Just Happened?
      6. Summary
    11. 6. Working with Images
      1. Drawing Images
        1. Using the Image Class
        2. Using the Bitmap Class
        3. Displaying Images
            1. Time for Action—Displaying Images
              1. What Just Happened?
        4. Image Effects
        5. Skewing, Rotation, and Scaling
      2. Building the ImageWarper Class
            1. Time for Action—Creating the ImageWarper Class
              1. What Just Happened?
        1. The ImageWarperControl
            1. Time for Action—Creating the ImageWarperApp and the Image WarperControl
              1. What Just Happened?
      3. Summary
    12. 7. Printing
      1. .NET Printing Explained
        1. Using the PrintDocument Class
      2. Your First Print Job
            1. Time for Action—Creating the "Hello Printer!" Application
              1. What Just Happened?
      3. The SimpleReportPrinter
        1. Building the SimpleReportPrinter and TextDispenser Classes
            1. Time for Action—Building the TextDispenser Class
              1. What Just Happened?
            2. Time for Action—Building the SimpleReportPrinter Class
              1. What Just Happened?
        2. User Involvement
        3. Our Responsibilities as Programmers
      4. Printing Custom Controls
            1. Time for Action—Creating the PrintableRichTextBox
              1. What Just Happened?
      5. Summary
    13. 8. Collections
      1. Collections in the .NET Framework
        1. ArrayList
        2. Queue
        3. Stack
        4. SortedList
      2. Generics
      3. Building the Font Picker
            1. Time for Action—Building Font Picker
              1. What Just Happened?
      4. Summary
    14. 9. Double Buffering
      1. Introduction to Double Buffering
      2. The Scroll Bar
        1. Scroll that Text!
            1. Time for Action—Building FlickerFree Control
              1. What Just Happened?
      3. Summary
    15. 10. Handling Mouse Events
      1. Handling Mouse Events
        1. Working with Coordinates
      2. Dragging and Dropping
        1. Dragging
            1. Time for Action—Dragging
              1. What Just Happened?
        2. Dragging and Dropping
            1. Time for Action—Dragging and Dropping.
              1. What Just Happened?
      3. Summary
    16. 11. Implementing Design-Time Support
      1. Building Designer-Friendly Controls
        1. Attributes
        2. Designers
        3. Type Converters
        4. UI Type Editors
        5. Property Editors
          1. Creating Property Editors
            1. Time for Action—Adding Design-Time Support
              1. What Just Happened?
      2. Summary
    17. 12. Designing Intuitive Interfaces
      1. The Relationship between User and Computer
        1. Communicating with Users
      2. Requests, Input Parsing, Fault Tolerance, and Feedback
        1. Examining the Sketcher Control
      3. Looking Further Into Input Parsing
        1. How Can We Use Regex to Our Advantage?
            1. Time for Action—Creating the Regex Application
              1. What Just Happened?
        2. Our Regex Pattern in Detail
      4. Optimization and Coding Conventions
      5. Summary
    18. 13. The PieChart Control
      1. Creating the PieChart Control
            1. Time for Action—Creating the PieChart Control
              1. What Just Happened?
      2. Adding Slice Names and Delimiters
            1. Time for Action—Improving the PieChart Control
              1. What Just Happened?
      3. PieChart Legend
            1. Time for Action—Creating the PieChart Legend
              1. What Just Happened?
      4. Printing the PieChart
            1. Time for Action—The Printable PieChart
              1. What Just Happened?
      5. Adding and Removing Slices
            1. Time for Action—Add Application Support for PieChart Slice Add/Remove Operations
              1. What Just Happened?
      6. Summary
    19. 14. Distributing Custom Controls
      1. Creating a Control Library Using Visual Studio 2005
      2. Creating a Control Library Using Visual C# Express 2005
      3. Using a Custom Control Library
    20. A. Distributing Custom Controls
      1. Creating a Control Library Using Visual Studio 2005
      2. Creating a Control Library Using Visual C# Express 2005
      3. Using a Custom Control Library