Windows Forms Programming in C#

Windows Forms Programming in C#

4.3 3
by Chris Sells

Praise for Windows Forms Programming in C#

“Chris may have a strong affinity for semi-colons, but anybody who’s programming Windows Forms needs to read this book.”

     —Brian Randell, Visual Basic Guru and DevelopMentor Instructor

“Chris Sells has done it again. This book has

See more details below


Praise for Windows Forms Programming in C#

“Chris may have a strong affinity for semi-colons, but anybody who’s programming Windows Forms needs to read this book.”

     —Brian Randell, Visual Basic Guru and DevelopMentor Instructor

“Chris Sells has done it again. This book has everything a developer needs to know to write serious WinForms applications. Chris leaves no stone unturned in explaining the WinForms programming model and arming developers with the knowledge they need to exploit WinForms to the fullest. And, as if that weren’t enough, Chris’s writing style makes this book a page-turner for geeks. I couldn’t put it down! Until John Grisham gets the .NET religion, you won’t find a better WinForms book anywhere.”

     —Jeff Prosise, co-founder of Wintellect, author of Programming Microsoft .NET

“Chris is clearly *the* expert on web deployment of WinForms. In this book, Chris explains this material clearly and the power of the technology really shows. Unlike other WinForms books, this manuscript takes a more practical approach to the use of programming tools, such as Visual Studio. Sells’s book strikes a nice balance between theory and practice. Windows Forms is an important technology that needs more press. Chris Sells’ book is in great position to be the definitive work on the emerging technology.”

     —Brian Graff, Sr. SW Engineer, PreEmptive Solutions, Inc.

“Chris has written the best WinForms book around. Period.”

     —Pierre Nallet, DevelopMentor Instructor

“Chris does a nice job of presenting the core elements of WinForms complete with many concise samples and graphic depictions of UI features in action. Even more compelling, however, is how Chris anticipates how most developers will want to use these features, and presents techniques and paradigms of usage that will be invaluable for any serious WinForms developer. This book is destined to become dog-eared in the hands anyone building WinForms applications.”

     —Fritz Onion, DevelopMentor instructor and author of Essential ASP.NET

“I don’t want just a description of the WinForms widgets. I can get that online or from other books. What I want is a roadmap for pitfalls to avoid, and innovative solutions for common problems. That is where this book shines.”

     —Johan Ericcson, SW Engineer, Agilent

“This is the definitive book for every Windows Programmer.”

     —Fumiaki Yoshimatsu, Sr. Engineer, Intoferia Corporation

“After browsing through countless books that introduce me to Windows Forms basics, it is refreshing to find a book that dives right into some real hard-core programming. This is, without a doubt the best and most useful C#/WinForms book I have ever read. I would suggest this book to be essential reading for very serious .NET WinForms developer who wants to work smarter instead of harder.”

     —Serge Shimanovsky, Software Developer, Rueters Group PLC

“In this book, Chris Sells discusses how the Windows Forms classes and their supporting infrastructure can be used to write robust and rich smart client applications. If you’re an experienced Windows programmer who has previously used MFC or directly utilized the Win32 API to write such applications, you will find Chris’s direct delivery very appropriate for transferring your knowledge to the managed classes. If you’re a developer with less Windows development experience, you’ll find the treatment of core concepts in application UI programming indispensable.”

     —From the foreword by Mike Blaszczack, Architect, SQL Server Data Warehousing, Microsoft

"I think this book does a great job of hitting a huge number of features—sometimes I forget how much there is to WinForms!" —Chris Anderson, Software Architect, Microsoft Windows Forms team

Programming Windows Forms in C# is the ultimate guide to using the Microsoft .NET forms package. Readers learn how to build smart client applications that take full advantage of both the rich user interface features of the Microsoft Windows operating system and the deployment features of HTML-based applications. Author Chris Sells draws upon his WinForms research and programming experience to provide what the Windows Forms documentation could not: a clear picture of exactly how C# programmers will want to use WinForms.

Well-written and easy to navigate, this book presents the building blocks of WinForms and the best practices for creating stand-alone client applications and front ends to databases and Web services. Readers gain an understanding of the rationale behind aspects of WinForms' design and will find out how to avoid or solve common problems. Figures illustrate WinForms' user interface features and code samples are used throughout the book to demonstrate best practices. All code has been tested with Visual Studio .NET 1.1 and is available at, where readers will also find updates to the book.

This book focuses on the topics readers need to understand in order to build real-world applications. These topics include:

Form layout

  • Multiple top-level windows
  • Non-rectangular windows
  • Accessing data from the middle tier, filesystems, XML, databases, and Web services
  • Classes outside the System.WinForms namespace, including System.Drawing and System.Security
  • Custom drawing
  • Hosting and building controls
  • Design-time integration
  • Data binding
  • Multithreaded user interfaces
  • Deploying WinForms over the Web
  • Moving from MFC
  • Delegates and events
  • Serialization basics

Programming Windows Forms in C# is the tutorial for experienced Windows programmers who are serious about mastering Windows Forms.

Read More

Product Details

Publication date:
Microsoft Windows Development Series
Edition description:
Older Edition
Product dimensions:
6.80(w) x 9.00(h) x 1.60(d)

Table of Contents





1. Hello, Windows Forms.

WinForms from Scratch.

Windows Forms in Visual Studio .NET.

Arranging Controls.


Application Settings.



Drawing and Printing.

Data Binding.

Multithreaded User Interfaces.


Moving from MFC.

Where Are We?

2. Forms.

Showing Forms.

Owner and Owned Forms.

Form Lifetime.

Form Size and Location.

Restricting Form Size.


Form Adornments.

Form Transparency.

Nonrectangular Forms.

Form Menus.

Context Menus.

Child Controls.

Control Z-Order.

Control Tab Order.

Themed Controls.

Hosting COM Controls.


Form Auto-Scaling.



Docking and Z-Order.



Custom Layout.

Multiple Document Interface.

Menu Merging.

Visual Inheritance.

Where Are We?

3. Dialogs.

Standard Dialogs.


Setting Modal Versus Modeless Behavior Dynamically.

Data Exchange.

Handling OK and Cancel.

Modeless Form Data.

Data Validation.

Regular Expressions and Validation.

Data Format Notification.

Thorough Validation.

Implementing Help.


Using the ErrorProvider for General Information.

Handling the Help Button and F1.

Using HTML Help.

Compiled HTML Help.

Using the HelpProvider Component.

Showing Help Contents, Index, and Search.

Where Are We?

4. Drawing Basics.

Drawing to the Screen.

Handling the Paint Event.

Triggering the Paint Event.


Known Colors.

Color Translation.


Solid Brushes.

Texture Brushes.

Hatch Brushes.

Linear Gradient Brushes.

Path Gradient Brushes.


Line Caps.




Creating Pens from Brushes.



Smoothing Modes.

Saving and Restoring Graphics Settings.


Fill Modes.


Loading and Drawing Images.

Scaling, Clipping, Panning, and Skewing.

Rotating and Flipping.




Drawing to Images.



Where Are We?

5. Drawing Text.


Creating Fonts.

Font Families.

Font Characteristics.

Font Height.



Strings and Paths.

Where Are We?

6. Advanced Drawing.

Page Units.

Converting Pixels to Page Units.



Scaling Fonts.




Combining Transforms.

Transformation Helpers.

Path Transformations.


Constructing and Filling a Region.

Clipping to a Region.

Region Combination Operations.

Optimized Drawing.

Double Buffering.

Other Drawing Options.

Where Are We?

7. Printing.

Print Documents.

Print Controllers.

Print Preview.

Basic Print Events.


Page Settings.

Printer Settings.

Print Range.

Targeting the Printer.

Where Are We?

8. Controls.

Standard Controls.

Action Controls.

Value Controls.

List Controls.

Container Controls.


Owner-Draw Controls.

Custom Controls.

Deriving Directly from the Control Class.

Testing Custom Controls.

Control Rendering.

Ambient Properties.

Custom Functionality.

Control Input.

Windows Message Handling.

Scrolling Controls.

Extending Existing Controls.

User Controls.

Drag and Drop.

The Drop Target.

The Drop Source.

Where Are We?

9. Design-Time Integration.


Standard Components.

Custom Components.

Design-Time Integration Basics.

Hosts, Containers, and Sites.

Debugging Design-Time Functionality.

The DesignMode Property.


Property Browser Integration.

Code Serialization.

Batch Initialization.

Extender Property Providers.

Type Converters.

Expandable Object Converter.

UI Type Editors.

Drop-Down UI Type Editors.

Modal UI Type Editors.

Custom Designers.

Design-Time-Only Properties.

Design-Time Context Menu Verbs.

Where Are We?

10. Resources.

Resource Basics.

Manifest Resources.

Typed Resources.

Resource Manager.

Designer Resources.

Resource Localization.

Culture Information.

Resource Probing.

Resource Localization.

Resource Localization for Nondevelopers.

Resource Resolution.

Input Language.

Where Are We?

11. Applications and Settings.


Application Lifetime.

Application Context.

Application Events.

UI Thread Exceptions.

Single-Instance Applications.

Passing Command Line Arguments.

Multi-SDI Applications.


Compile-Time Settings.

Environment Settings.


Types of Settings.

.config Files.

Dynamic Properties.

The Registry.

Special Folders.

Settings and Streams.

Isolated Storage.

Versioned Data Paths.

Choosing a Settings Mechanism.

Where Are We?

12. Data Sets and Designer Support.

Data Sets.

Retrieving Data.

Creating Data.

Updating Data.

Deleting Data.

Tracking Changes.

Committing Changes.

Multitable Data Sets.





Designer Support.

Connection Objects.

Command Objects.

Data Adapter Objects.

Typed Data Sets.

Creating a Typed Data Set.

Constraints in Typed Data Sets.

Relations in Typed Data Sets.

Expressions in Typed Data Sets.

Adding a Typed Data Set to a Form.

Where Are We?

13. Data Binding and Data Grids.

Data Binding.

Bindings and Data Sources.

Simple Data Binding to Items.

Simple Data Binding to Lists

Simple Binding to Data Sets.

Binding Managers.

Current Data Row.

Changes to the Data Set.

Changes to the Control.

Complex Data Binding.

Data Views.

Master-Detail Relations.

Data Grids.

Formatting Data Grids.

Data Exchange and Data Grids.

Bringing It All Together.

Custom Data Sources.

Custom Item Data Sources.

Type Descriptors and Data Binding.

Type Conversion.

List Data Sources.

Where Are We?

14. Multithreaded User Interfaces.

Long-Running Operations.

Progress Indication.

Asynchronous Operations.

Safety and Multithreading.

Simplified Multithreading.


Communication with Shared Data.

Communicating via Method Parameters.

Communication via Message Passing.

Asynchronous Web Services.

Where Are We?

15. Web Deployment.

Hosting Controls in Internet Explorer.

Control Creation.

Control Interaction.

Code Access Security.

Checking for Permissions.

Awarding Permissions.

No-Touch Deployment.

Application Download.


Related Files.

Partially Trusted Assembly Considerations.

Allowing Partially Trusted Callers.


Custom User Input.

Communicating via Web Services.

Reading and Writing Files.

Command Line Arguments.

Debugging NTD Applications.

Increasing Permissions.

Increasing Permissions Programmatically.

Deploying Permissions.


Where Are We?

A. Moving from MFC.

A Few Words About MFC.

MFC Versus WinForms.

The Differences.



B. Delegates and Events.



Harvesting All Results.

Asynchronous Notification: Fire and Forget.

Happiness in the Universe.

C. Serialization Basics.



Skipping a Nonserialized Field.



Data Versioning.

D. Standard WinForms Components and Controls.

Components and Controls Defined.

Standard Components.

Standard Dialogs.

Notify Icons.


Image List.

Main Menus and Context Menus.

Standard Controls.

Non-Container Controls.

Container Controls.


Index. 0321116208T08272003

Read More

Customer Reviews

Average Review:

Write a Review

and post it to your social network


Most Helpful Customer Reviews

See all customer reviews >