Using many examples all on a common theme, this second edition of Windows Forms Programming with C# presents Windows application development in a step-by-step, easy to follow format. Written for beginner and intermediate programmers eager to get their hands dirty, the text covers fundamentals like labels, buttons, and tool strips, as well as advanced concepts like owner-drawn lists, custom controls, and two-way data binding.
The book is a tutorial, leading the reader through Windows application development using C# and Visual Studio .NET. It illustrates how the classes in the .NET Framework interact in a fully functional application. Material added for the second edition includes coverage of the .NET 2.0 Framework, extender providers, cryptographic classes, and application deployment.
Author(s): Erik Brown
Edition: 2
Publisher: Manning Publications
Year: 2006
Language: English
Pages: 752
Windows Forms in Action, Second Edition
preface
preface to the first edition
acknowledgments
about this book
what’s new in 2.0
PART 1 Hello Windows Forms
Getting started with Windows Forms
1.1 Programming in C#
1.1.1 Namespaces and classes
1.1.2 Constructors and methods
1.1.3 C# types
1.1.4 The Main method
1.1.5 The Application class
1.1.6 Program execution
1.2 Windows Forms controls
1.2.1 The using directive
1.2.2 The Control class
1.2.3 The Controls property
1.3 Loading files
1.3.1 Events
1.3.2 The OpenFileDialog class
1.3.3 Bitmap images
1.4 Resizing forms
1.4.1 The Anchor property
1.4.2 The Dock property
1.5 Recap
Getting started with Visual Studio
2.1 Programming with Visual Studio
2.1.1 Creating a project
2.1.2 Executing a program
2.1.3 Viewing the source code
2.2 Windows Forms controls
2.2.1 The AssemblyInfo file
2.2.2 Renaming a form
2.2.3 The Toolbox window
2.3 Loading files
2.3.1 Handling events in Visual Studio
2.3.2 Handling exceptions
2.4 Resizing forms
2.4.1 Assigning the Anchor property
2.4.2 Assigning the Dock property
2.5 Recap
PART 2 Basic Windows Forms
Menus
3.1 Controls and containers
3.1.1 Control classes
3.1.2 Container classes
3.2 The nature of menus
3.2.1 Menu terminology
3.2.2 Menus in .NET
3.3 Menu bars
3.3.1 Adding a menu strip
3.3.2 Adding a menu item
3.3.3 Adding drop-down menu items
3.4 Menu handling
3.4.1 Adding handlers via the designer window
3.4.2 Adding handlers via the properties window
3.5 Recap
Context menu and status strips
4.1 Context menu strips
4.1.1 Creating a context menu
4.1.2 Adding items to a context menu
4.1.3 Sharing a context menu
4.2 Drop-down events and event arguments
4.2.1 Handling a submenu item click
4.2.2 Altering a submenu before it appears
4.3 Status strips
4.3.1 Creating a status strip
4.3.2 Adding status strip labels
4.4 Recap
Reusable libraries
5.1 Class libraries
5.1.1 Creating a class library
5.1.2 Using the command-line tools
5.1.3 Creating the Photograph class
5.1.4 Defining class properties
5.2 The object class
5.2.1 Comparing object and Object
5.2.2 Overriding object methods
5.3 Interfaces
5.3.1 Interfaces and collections
5.3.2 Appreciating collection classes
5.4 Generics
5.4.1 Generic classes
5.4.2 Appreciating generic collections
5.4.3 Disposing of resources
5.5 Recap
Files and common dialog boxes
6.1 Standard menus
6.1.1 Changing the menu bar
6.1.2 Managing an album
6.2 Common file dialog boxes
6.2.1 Creating a new album
6.2.2 Opening an album
6.2.3 Saving an album
6.2.4 Printing and exiting
6.3 Streams and writers
6.3.1 Stream classes
6.3.2 Writing an album to disk
6.3.3 Reading an album from disk
6.4 Album management
6.4.1 Adding and removing images
6.4.2 Navigating an album
6.4.3 Displaying album status
6.5 Recap
Dialog boxes
7.1 Message boxes
7.1.1 Creating an OK message box
7.1.2 Creating a YesNo message box
7.1.3 Creating a YesNoCancel message box
7.2 The Form.Close method
7.2.1 Comparing Close and Dispose
7.2.2 Intercepting the Form.Close method
7.3 Forms and panels
7.3.1 The Form class
7.3.2 Creating a dialog box
7.4 Modeless dialog boxes
7.4.1 Creating a modeless dialog box
7.4.2 Adding panels and labels to a form
7.4.3 Updating the PixelDialog controls
7.4.4 Displaying a modeless dialog box
7.4.5 Updating the PixelDialog form
7.4.6 Tracking mouse movement
7.5 Recap
Text boxes
8.1 Form inheritance
8.1.1 Creating a base form
8.1.2 Creating a derived form
8.2 Standard text boxes
8.2.1 Adding text boxes
8.2.2 Adding a multiline text box
8.2.3 Hooking up a dialog box
8.3 Masked text boxes
8.3.1 Handling key presses
8.3.2 Masking text
8.4 Recap
Buttons
9.1 Push buttons
9.1.1 The Button class
9.1.2 Expanding the PhotoAlbum class
9.1.3 Storing album data
9.2 Radio buttons
9.2.1 The RadioButton class
9.2.2 Creating an album dialog box
9.3 Check box buttons
9.3.1 The CheckBox class
9.3.2 Using check box buttons
9.3.3 Completing the AlbumEditDialog form
9.3.4 Hooking up a dialog box (again)
9.4 Tooltips and error providers
9.4.1 The ToolTip class
9.4.2 Displaying tooltips
9.4.3 Building extender providers
9.4.4 The ErrorProvider class
9.5 Recap
Handling user input and encryption
10.1 Keyboard events
10.1.1 The three events
10.1.2 Handling the KeyPress event
10.1.3 Handling the KeyDown and KeyUp events
10.1.4 Preprocessing command keys
10.2 Mouse events
10.2.1 The MouseEventArgs class
10.2.2 Implementing FlybyTextProvider using mouse events
10.2.3 Using the FlybyTextProvider class
10.3 Encryption
10.3.1 The Cryptography namespace
10.3.2 Encrypting data
10.3.3 Writing encrypted data
10.3.4 Reading encrypted data
10.3.5 Storing encrypted albums
10.4 Link labels
10.4.1 The LinkLabel class
10.4.2 Saving encrypted albums
10.4.3 Opening encrypted albums
10.5 Recap
List boxes
11.1 List controls
11.1.1 The ListControl classes
11.1.2 Creating a new solution
11.1.3 Refactoring application code
11.2 Simple list boxes
11.2.1 The ListBox class
11.2.2 Displaying a data source
11.2.3 Selecting list items
11.3 Multiselection list boxes
11.3.1 Enabling multiple selection
11.3.2 Reordering list items
11.3.3 Removing list items
11.4 Recap
Combo boxes
12.1 Standard combo boxes
12.1.1 The ComboBox class
12.1.2 Creating a combo box
12.1.3 Selecting combo box items
12.1.4 Modifying the data source
12.2 Editable combo boxes
12.2.1 Creating a combo box (again)
12.2.2 Updating a combo box dynamically
12.3 Automatic completion
12.3.1 Understanding automatic completion
12.3.2 Using auto-completion in a combo box
12.4 Item formatting
12.4.1 The formatting interfaces
12.4.2 Implementing an IFormattable interface
12.4.3 Using formatting in list controls
12.4.4 Implementing custom formatters
12.5 Recap
Tab controls and pages
13.1 Tab control fundamentals
13.1.1 The TabControl class
13.1.2 Creating tab controls
13.2 Tab page fundamentals
13.2.1 The TabPage class
13.2.2 Creating tab pages
13.2.3 Enclosing existing controls in a tab page
13.3 Owner-drawn tabs
13.3.1 The DrawItem event
13.3.2 Drawing page tabs
13.3.3 Using a custom tab control
13.4 Owner-drawn list boxes
13.4.1 Custom list items
13.4.2 Assigning item size
13.4.3 Drawing list items
13.5 Recap
Dates, calendars, and progress bars
14.1 Date and time display
14.1.1 The DateTimePicker class
14.1.2 Creating a DateTimePicker control
14.2 Date and time formats
14.2.1 Formatting date and time values
14.2.2 Customizing a DateTimePicker control
14.3 Calendars
14.3.1 The MonthCalendar class
14.3.2 The UserControl class
14.3.3 Creating a calendar control
14.3.4 Initializing a calendar
14.3.5 Handling mouse clicks in a calendar control
14.4 Progress bars
14.4.1 Creating an images user control
14.4.2 The ProgressBar class
14.4.3 Performing a background task
14.5 Recap
Bells and whistles
15.1 Images and cursors
15.1.1 Bitmaps
15.1.2 Icons
15.1.3 Cursors
15.2 Embedded resources and sounds
15.2.1 Embedding a resource
15.2.2 Using the project resource file
15.2.3 Playing a sound
15.3 Track bars
15.3.1 The TrackBar class
15.3.2 Using track bars
15.4 Timers
15.4.1 The Timer class
15.4.2 Using timers
15.5 Recap
Tool strips
16.1 Tool strip fundamentals
16.1.1 The ToolStrip classes
16.1.2 Creating a tool strip
16.2 Tool strip item fundamentals
16.2.1 The ToolStripItem classes
16.2.2 Adding standard tool strip items
16.2.3 Item alignment, overflow, and other features
16.3 Image lists
16.3.1 The ImageList class
16.3.2 Creating an image list
16.3.3 Adding custom tool strip buttons
16.4 Tool strip containers
16.4.1 The ToolStripContainer class
16.4.2 Embedding a tool strip in a container
16.5 Specialized button items
16.5.1 Toggle buttons
16.5.2 Drop-down buttons
16.5.3 Split buttons
16.6 Recap
PART 3 Advanced Windows Forms
Custom controls
17.1 Extending existing controls
17.1.1 Designing a scrollable picture box
17.1.2 Creating a scrollable picture box
17.1.3 Implementing a scrollable picture box
17.2 Control-based classes
17.2.1 Creating a Control-based class
17.2.2 Common features of custom controls
17.3 The ScrollablePictureBox class
17.3.1 Painting the control
17.3.2 Resizing the control
17.3.3 Handling property changes
17.4 User controls
17.5 Custom controls in Visual Studio
17.5.1 Customizing class behavior
17.5.2 Customizing class member behavior
17.5.3 Customizing design time behavior
17.6 Recap
Explorer interfaces and tree views
18.1 Interface styles
18.1.1 Single document interfaces
18.1.2 Multiple document interfaces
18.1.3 Explorer interfaces
18.2 Explorer interfaces in .NET
18.2.1 The SplitContainer class
18.2.2 The TreeView class
18.2.3 Creating an explorer interface
18.3 Tree nodes
18.3.1 The TreeNode class
18.3.2 Creating tree nodes
18.4 Custom tree views
18.4.1 Creating a custom tree view
18.4.2 Creating custom tree nodes
18.4.3 Using interfaces with custom nodes
18.4.4 Expanding and collapsing tree nodes
18.4.5 Selecting and editing tree nodes
18.4.6 Integrating a custom tree view control
18.5 Recap
List views
19.1 List view fundamentals
19.1.1 The ListView class
19.1.2 Creating a list view
19.1.3 Populating a list view
19.2 List view columns
19.2.1 Defining column headers
19.2.2 Populating list view columns
19.2.3 Sorting list view columns
19.3 List view features
19.3.1 Selecting items
19.3.2 Editing item labels
19.3.3 Activating items
19.4 Virtual Items
19.5 Recap
Multiple document interfaces
20.1 MDI forms
20.1.1 Creating an MDI container
20.1.2 Creating an MDI child
20.1.3 Updating the entry point
20.2 Merged menus
20.2.1 Assigning merge actions
20.2.2 Assigning merge indexes
20.2.3 Opening and closing child forms
20.3 MDI children
20.3.1 Merging tool strips
20.3.2 Displaying pixel data
20.3.3 Opening an album twice
20.3.4 Updating the title bar
20.4 MDI child window management
20.4.1 Arranging MDI children
20.4.2 Displaying an MDI child list menu
20.5 Recap
Data binding
21.1 Data grid views
21.1.1 The DataGridView class
21.1.2 Creating a data grid view
21.1.3 Populating a data grid view
21.2 Columns and rows
21.2.1 Creating columns
21.2.2 Creating combo box columns
21.2.3 Understanding bands and rows
21.3 Cells
21.3.1 The DataGridViewCell class
21.3.2 Using the cell class
21.3.3 Saving a modified album
21.4 Recap
Two-way binding and binding sources
22.1 Binding lists
22.1.1 The IBindingList interface
22.1.2 Creating a binding list
22.2 Editable objects
22.2.1 The IEditableObject interface
22.2.2 Creating an editable object
22.3 Simple data binding
22.3.1 The BindingSource class
22.3.2 Altering the MyAlbumData application
22.3.3 Performing simple binding
22.3.4 Updating data bound controls
22.3.5 Binding navigators
22.4 Recap
Odds and ends .NET
23.1 Printing
23.1.1 Using the print classes
23.1.2 Drawing a print page
23.2 Drag-and-drop
23.2.1 Initiating drag-and-drop
23.2.2 Receiving drag-and-drop
23.3 Web browsing
23.3.1 Creating an about box
23.3.2 The WebBrowser class
23.3.3 Browse to a web site
23.4 Application settings
23.4.1 Storing the Location setting
23.4.2 Defining a custom setting
23.5 Deployment
23.5.1 Creating a setup project
23.5.2 Publishing a ClickOnce application
23.6 Recap
Appendix A
A.1 C# programs
A.1.1 Assemblies
A.1.2 Namespaces
A.2 Types
A.2.1 Classes
A.2.2 Structures
A.2.3 Interfaces
A.2.4 Enumerations
A.2.5 Delegates
A.3 Language elements
A.3.1 Built-in types
A.3.2 Operators
A.3.3 Keywords
A.4 Special features
A.4.1 Exceptions
A.4.2 Arrays
A.4.3 Generics
A.4.4 Main
A.4.5 Boxing
A.4.6 Documentation
Appendix B .NET namespaces
B.1 System.Collections
B.2 System.ComponentModel
B.3 System.Data
B.4 System.Drawing
B.5 System.Globalization
B.6 System.IO
B.7 System.Net
B.8 System.Reflection
B.9 System.Resources
B.10 System.Security
B.11 System.Threading
B.12 System.Web
B.13 System.Windows.Forms
B.14 System.Xml
Appendix C Visual index
C.1 Objects (part 1)
C.2 Objects (part 2)
C.3 Marshal by reference objects
C.4 Components
C.5 Common dialogs
C.6 Controls (part 1)
C.7 Controls (part 2)
C.8 Scrollable controls
C.9 Container controls
C.10 Tool strip item classes
C.11 Enumerations
C.12 Event data
C.13 Interfaces
Appendix D For more information
index