ebook img

User Interfaces in C#: Windows Forms and Custom Controls PDF

614 Pages·2002·15.74 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview User Interfaces in C#: Windows Forms and Custom Controls

Praise for the first printing of User Interfaces in C#: Windows Forms and Custom Controls: "For more in-depth user interface work ... Highly recommended." -David Groves, contributor to the www.devhood.com discussion group "Overall, I must commend on the author's efforts to make the book an enjoyable read." -Timmy, contributor to the www. tech -critic.com discussion group ''Apress has created a reputation for publishing the best books on specialty topics like this, and Matthew MacDonald is one of the most experienced and seasoned technology writers. Together, they have created a great book that will be exactly what experienced programmers are looking for. The 'Expert's Voice' on the technology is combined with a detailed discussion of good user-interface design principles to give you the information you need about how to design elegant user interfaces users will love. "In addition, you'll learn how and why to extend the user interface with your own custom controls. VB .NET's object-oriented revolution makes it a requirement now to create your own controls that are scalable, flexible, and reusable." -Dan Mabbutt, About.com's Visual Basic Guide (http://visualbasic.about.com) Praise for Matthew MacDonald's other books: Peer-to-Peer with VB .NET (1590591054) "Check this one out. Very good author!" -Hazzard, contributor to the www.developersdex.com discussion group User Interfaces in C#: Windows Forms and Custom Controls MATIHEWMACDONALD APress Media, LLC User Interfaces in C#: Windows Forms and Custom Controls Copyright ©2002 by Matthew MacDonald Originally published by Apress in 2002 All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN 978-1-59059-045-4 ISBN 978-1-4302-0837-2 (eBook) DOI 10.1007/978-1-4302-0837-2 'IIademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Technical Reviewer: Gordon Henshaw Editorial Directors: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis, Jason Gilmore, Chris Mills, Dominic Shakeshaft, Jim Sumser, Karen Watterson, John Zukowski Managing Editor: Grace Wong Copy Editor: Anne Friedman Production Editor: Karl Brooks Project Manager: Sofia Marchant Compositor: Diana Van Wmkle, Van Wmkle Design Artist: Kurt Krames Indexer: Nancy A. Guenther Cover Designer: Kurt Krames Manufacturing Manager: Tom Debolski Marketing Manager: Stephanie Rodriguez The information in this book is distributed on an "as is" basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author nor Apress shall have any liability to any person or entity With respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at http: I !'IMN. a press. com in the Downloads section. For Razia and Hamid Contents at a Glance Preface .................................................................................................................. xvii About the Author ............................................................................................... xix About the Technical Reviewer ...................................................................... xx Acknowledgments .................................................................................................. xxi Introduction ...................................................................................................... xxiii Chapter Creating Usable Interfaces ..................................... 1 1 Chapter 2 Designing with Classes and Tiers .................... 23 Chapter 3 Control Class Basics ................................................... 57 Chapter 4 Classic Controls .............................................................. 83 Chapter 5 Forms ........................................................................................ 143 Chapter 6 Modern Controls .............................................................. 201 Chapter 7 Custom Controls .............................................................. 259 Chapter 8 Design-Time Support for Custom Controls .. 309 Chapter 9 Data Controls .................................................................... 349 Chapter 10 MDI Interfaces and Works paces .......................... 399 Chapter Dynamic User Interface ........................................... 11 .435 Chapter 12 GDI+ Basics ........................................................................ .465 Chapter 13 GDI+ Controls .................................................................... so1 Chapter 14 Help and Application-Embedded Support ..... 531 Index .................................................................................................................... 561 v Contents Preface .................................................................................................................. xvii About the Author ............................................................................................... xix About the Technical Reviewer ...................................................................... xx Acknowledgments .................................................................................................. xxi Introduction ...................................................................................................... xxiii Chapter 1 Creating Usable Interfaces ..................................... 1 Why Worry About the Interface? .................................................................. 2 A Brief History of User Interfaces ......................................................... 3 The Command-Line Era .................................................................................... 3 The Question-Answer Model ............................................................................ 5 The Menu-Driven Model ................................................................................... 7 The GUI Era ........................................................................................................ 8 Creativity vs. Convention ........................................................................... 10 Consistency in .NET ......................................................................................... 11 The ''Act-Like-Microsoft" Principle ................................................................. 11 Administrative Utilities .................................................................................... 12 Know Your Application Type ............................................................................ 13 Know Your User ................................................................................................ 14 Handling Complexity ........................................................................................ 15 Segiilenting Information ................................................................................. 16 Inductive User Interface .................................................................................. 17 Helpful Restrictions ...................................................................................... 17 Restricting the User's Ability to Make a Mistake ............................................ 17 Restricting the User's Choices ......................................................................... 18 Restricting the User's Imagination .................................................................. 19 Programming User Interface for the Web .............................................. 20 The Last Word ..................................................................................................... 21 Chapter 2 Designing with Classes and Tiers .................... 23 Classes and Objects ........................................................................................ 24 The Roles of Classes ......................................................................................... 24 Classes and Types ............................................................................................. 25 More About Objects ......................................................................................... 28 vii Contents User Interface Classes in • NET ................................................................ 29 Controls Are Classes ......................................................................................... 29 Controls Contain Other Controls .................................................................... 30 Controls Derive from Other Controls ............................................................. 33 Inheritance and the Form Class ...................................................................... 35 The Controls Collection ................................................................................... 36 Generating Code with Visual Studio .NET ...................................................... 37 Interacting with a Control ........................................................................ 39 .The View-Mediator Pattern ............................................................................. 40 Smart Controls .................................................................................................. 42 Smart Forms ..................................................................................................... 43 Encapsulation ..................................................................................................... 44 Use Enumerations and Resource Classes ...................................................... .44 Use Collections ................................................................................................. 45 Restrain from Sharing Control References .................................................... .45 Define a Data Transfer Plan ............................................................................. 45 Use a Central Switchboard .............................................................................. 45 Create Data-Driven User Interfaces ................................................................ 46 Developing in Tiers ........................................................................................ 47 Problems with Three-Tier Design ................................................................... 48 Three-Tier Design Consistency ....................................................................... 50 Fixing Three-Tier Design ............................................................................. 51 Using the DataSet ............................................................................................ 52 Other Types of Application .............................................................................. 54 The Last Word ..................................................................................................... 54 Chapter 3 Control Class Basics ................................................... 57 The Windows Forms Package ........................................................................... 57 The .NET Solution ............................................................................................ 56 The Control Class ............................................................................................ 60 Position and Size ............................................................................................ 64 Color ...................................................................................................................... 66 Fonts and Text ................................................................................................... 69 Access Keys ....................................................................................................... 71 Control Relations ............................................................................................ 71 Focus and the Tab Sequence ........................................................................ 72 Responding to the Mouse and Keyboard ................................................... 75 A Mouse/Keyboard Example ........................................................................... 78 Mouse Cursors .................................................................................................. 79 Graphics and Painting ................................................................................... 79 Low-Level Members ............................................................................................ 81 The Last Word ..................................................................................................... 82 viii Contents Chapter 4 Classic Controls .............................................................. 83 Types of Controls ............................................................................................ 83 Invisible Controls ............................................................................................. 83 Provider Controls ............................................................................................. 85 ActiveX Controls ............................................................................................... 86 Should You Import ActiveX Controls? ............................................................. 89 The Classic Control Gallery ...................................................................... 90 Labels ................................................................................................................ 90 UnkLabel .......................................................................................................... 91 Button ................................................................................................................ 94 TextBox .............................................................................................................. 94 CheckBox and RadioButton ............................................................................ 96 PictureBox ......................................................................................................... 97 List Controls ...................................................................................................... 97 Other Domain Controls ................................................................................. 10 2 Organizational Controls ................................................................................ 10 4 The Date Controls .......................................................................................... 105 The DateTimePicker ...................................................................................... 10 6 MonthCalendar .............................................................................................. 108 Menus .................................................................................................................... 111 The Menu Class .............................................................................................. 112 The MainMenu and ContextMenu Classes .................................................. 114 The Menultem Class ...................................................................................... 115 The Visual Studio .NET Menu Designer ....................................................... 118 Attaching a Menu ........................................................................................... 118 Menu Events ................................................................................................... 119 Copying and Cloning a Menu ........................................................................ 121 Merging a Menu .............................................................................................. 121 Owner-Drawn Menus .......................................................................................... 122 An Owner-Drawn Menu Control ................................................................... 125 Drag-and-Drop ................................................................................................... 130 "Fake" Drag-and-Drop ................................................................................... 130 Authentic Drag-and-Drop ............................................................................. 132 Validation ......................................................................................................... 135 A Validation Example ..................................................................................... 136 Validating with the ErrorProvider ................................................................. 138 Validating with Regular Expressions ............................................................. 140 The Last Word ................................................................................................... 142 ix Contents Chapter 5 Forms ........................................................................................ 143 The Form Class ................................................................................................. 143 Form Size and Position .................................................................................. 148 Scrollable Forms ............................................................................................. 152 Showing a Form .............................................................................................. 154 Custom DialogWmdows ................................................................................ 155 Form Interaction ............................................................................................ 158 Form Ownership ............................................................................................ 161 WmdowsXP Styles ......................................................................................... 163 Prebuilt Dialogs ............................................................................................ 165 Resizable Forms .............................................................................................. 171 The Problem of Size ........................................................................................ 171 Minimum and Maximum Size ....................................................................... 172 Anchoring ....................................................................................................... 173 Docking ........................................................................................................... 177 Splitting Windows .......................................................................................... 180 Docking with Panels ....................................................................................... 181 Other SplitWmdows ....................................................................................... 183 Irregularly Shaped Forms ........................................................................... 186 Shaped Form Content .................................................................................... 188 Moving Shaped Forms ................................................................................... 190 Forms with Holes ............................................................................................ 192 Visual Inheritance ........................................................................................ 193 Making an Ancestor Control Available ......................................................... 195 Adding an Ancestor Property ........................................................................ 196 Overriding an Event Handler ......................................................................... 197 The Last Word ................................................................................................... 199 Chapter 6 Modern Controls .............................................................. 201 The ImageList ................................................................................................... 201 Dealing with the ImageList in Code .............................................................. 203 ListView and TreeView ................................................................................. 205 Basic ListView ................................................................................................. 206 Advanced ListView Tricks ........................................................................... 211 Label Editing ................................................................................................... 215 Adding Information to a ListView .................................................................2 16 Basic TreeView ................................................................................................. 217 TreeView Structure ......................................................................................... 218 TreeViewNavigation ...................................................................................... 219 Manipulating Nodes ...................................................................................... 223 Selecting Nodes .............................................................................................. 226 X

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.