Pro .NET 2.0 Windows Forms and Custom Controls in C#

1.1K 964 5
Pro .NET 2.0 Windows Forms and Custom Controls in C#

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Macdonald_4398Front.fm Page i Friday, November 18, 2005 5:14 PM Pro NET 2.0 Windows Forms and Custom Controls in C# ■■■ Matthew MacDonald Macdonald_4398Front.fm Page ii Friday, November 18, 2005 5:14 PM Pro NET 2.0 Windows Forms and Custom Controls in C# Copyright © 2006 by Matthew MacDonald 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 (pbk): 1-59059-439-8 Printed and bound in the United States of America Trademarked 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 Lead Editor: Dominic Shakeshaft Technical Reviewer: Christophe Nasarre Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis, Jason Gilmore, Jonathan Hassell, Chris Mills, Dominic Shakeshaft, Jim Sumser Associate Publisher: Grace Wong Project Manager: Beckie Brand Copy Edit Manager: Nicole LeClerc Copy Editor: Candace English Assistant Production Director: Kari Brooks-Copony Production Editor: Janet Vail Compositor: Susan Glinert Proofreader: Nancy Sixsmith Indexer: Michael Brinkman Artist: Kinetic Publishing Services, LLC Interior Designer: Van Winkle Design Group Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013 Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com, or visit http://www.springeronline.com For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710 Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http://www.apress.com 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(s) 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://www.apress.com in the Source Code section Macdonald_4398Front.fm Page iii Friday, November 18, 2005 5:14 PM For Nora and Paul Macdonald_4398Front.fm Page iv Friday, November 18, 2005 5:14 PM Macdonald_4398Front.fm Page v Friday, November 18, 2005 5:14 PM Contents at a Glance Foreword xxv About the Author xxvii About the Technical Reviewer xxix Acknowledgments xxxi Introduction xxxiii PART ■■■ Windows Forms Fundamentals ■CHAPTER User Interface Architecture ■CHAPTER Control Basics 41 ■CHAPTER Forms 73 ■CHAPTER The Classic Controls 111 ■CHAPTER Images and Resources 151 ■CHAPTER Lists and Trees 173 ■CHAPTER Drawing with GDI+ 211 ■CHAPTER Data Binding 263 PART ■■■ Custom Controls ■CHAPTER Custom Control Basics 321 ■CHAPTER 10 User Controls 337 ■CHAPTER 11 Derived Controls 365 ■CHAPTER 12 Owner-Drawn Controls 389 ■CHAPTER 13 Design-Time Support for Custom Controls 425 PART ■■■ Modern Controls ■CHAPTER 14 Tool, Menu, and Status Strips 477 ■CHAPTER 15 The DataGridView 521 ■CHAPTER 16 Sound and Video 579 ■CHAPTER 17 The WebBrowser 593 v Macdonald_4398Front.fm Page vi Friday, November 18, 2005 5:14 PM vi ■C O N T E N T S A T A G L A N C E PART ■■■ Windows Forms Techniques ■CHAPTER 18 Validation and Masked Editing 615 ■CHAPTER 19 Multiple and Single Document Interfaces 655 ■CHAPTER 20 Multithreading 693 ■CHAPTER 21 Dynamic Interfaces and Layout Engines 733 ■CHAPTER 22 Help Systems 781 PART ■■■ Advanced Custom Controls ■CHAPTER 23 Skinned Forms and Animated Buttons 815 ■CHAPTER 24 Dynamic Drawing with a Design Surface 845 ■CHAPTER 25 Custom Extender Providers 879 ■CHAPTER 26 Advanced Design-Time Support 893 ■APPENDIX A Creating Usable Interfaces 935 ■APPENDIX B ClickOnce 951 ■INDEX 971 Macdonald_4398Front.fm Page vii Friday, November 18, 2005 5:14 PM Contents Foreword xxv About the Author xxvii About the Technical Reviewer xxix Acknowledgments xxxi Introduction xxxiii PART ■■■ ■CHAPTER Windows Forms Fundamentals User Interface Architecture Classes and Objects The Roles of Classes Classes and Types User Interface Classes in NET Controls Are Classes Controls Can Contain Other Controls 10 Controls Can Extend Other Controls 12 Inheritance and the Form Class 14 Accessing Controls 16 Components 18 Interacting with a Control 19 Overriding Methods 20 The View-Mediator Pattern 20 Smart Controls 22 Smart Forms 22 Visual Studio 23 Generating User-Interface Code in Visual Studio 25 The Component Tray 27 The Hidden Designer Code 28 Application Lifetime 31 Designing Windows Forms Applications 33 Encapsulation 33 Developing in Tiers 36 The Last Word 39 vii c5b9fc1a45eb1e329bb0a9d79e858c51 Macdonald_4398Front.fm Page viii Friday, November 18, 2005 5:14 PM viii ■C O N T E N T S ■CHAPTER Control Basics 41 The Windows Forms Package 41 The NET Solution 42 The Control Class 43 Control Relations 46 Windows XP Styles 47 Position and Size 48 Overlapping Controls 50 Color 52 Alpha Blending 54 Fonts and Text 55 System Fonts 57 Large Fonts 57 Access Keys 58 Focus and the Tab Sequence 59 Responding to the Mouse and Keyboard 61 Handling the Keyboard 61 Handling the Mouse 66 A Mouse/Keyboard Example 67 Mouse Cursors 68 Low-Level Members 70 The Last Word 71 ■CHAPTER Forms 73 The Form Class 73 Form Size and Position 77 Scrollable Forms 81 Showing a Form 83 Custom Dialog Windows 83 Form Interaction 86 Form Ownership 89 Prebuilt Dialogs 91 Resizable Forms 94 The Problem of Size 95 Minimum and Maximum Form Size 96 Anchoring 96 Docking 100 Autosizing 101 Macdonald_4398Front.fm Page ix Friday, November 18, 2005 5:14 PM ■C O N T E N T S Splitting Windows 104 Building Split Windows with Panels 106 Other Split Windows 107 The Last Word 110 ■CHAPTER The Classic Controls 111 The Classic Control Gallery 111 Labels 111 LinkLabel 112 Button 114 TextBox 115 RichTextBox 117 CheckBox and RadioButton 122 PictureBox 122 List Controls 123 Other Domain Controls 127 The Date Controls 129 The DateTimePicker 130 MonthCalendar 132 Container Controls 134 The TabControl 135 AutoComplete 137 Drag-and-Drop 139 “Fake” Drag-and-Drop 139 Authentic Drag-and-Drop 140 Extender Providers 143 The NotifyIcon 145 ActiveX Controls 148 Should You Import ActiveX Controls? 149 The Last Word 150 ■CHAPTER Images and Resources 151 The Image Class 151 Common Controls and Images 152 The ImageList 154 ix Macdonald_4398Index.fm Page 1026 Sunday, November 20, 2005 5:15 PM 1026 ■I N D E X implementing GetXxx() and SetXxx() methods, 883–884 providing the extended property, 882 testing the provider, 885 StatusTextChanged event WebBrowser control, 597 Step property ProgressBar control, 339 Step() method ProgressBar control, 129 Stop() method IMediaControl interface, 584 SoundPlayer control, 580 WebBrowser control, 595 Stream property SoundPlayer control, 580 StreamChanged event SoundPlayer control, 580 Stretch property ToolStrip class, 488, 500 StringBuilder class System.Text namespace, 12 StringFormat class Alignment property, 232 EllipsisPath property, 232 FormatFlags property, 232 LineAlignment property, 232 Trimming property, 232 structures, introduction, Style property DataGridViewCell class, 546 StyleName property AnimatedButtonBase class, 843 Sunken value Border3DStyle enumeration, 494 SunkenInner value Border3DStyle enumeration, 494 SunkenOuter value Border3DStyle enumeration, 494 SupportsChangeNotification property IBindingList interface, 302 SupportsSearching property IBindingList interface, 302 SupportsSorting property IBindingList interface, 302 SuppressKeyPress property KeyPressEventArgs class, 65 SuspendLayout() method collection-based Windows Forms controls, 347 System namespace DateTime class, 131 System value ToolStripRenderMode enumeration, 515 System.Collections namespace ArrayList class, 88 Hashtable class, 88 System.ComponentModel namespace attributes, 428–429 attributes for control properties, 438 BackgroundWorker component, 712 Component class, 631, 886 DefaultValueAttribute class, 438, 439 IExtenderProvider interface, 881 License class, 928 LicenseProvider class, 928 MaskedTextProvider class, 650 ProvideProperty attribute, 881 type converters, 446 TypeConverter class, 448 TypeDescriptor class, 896 System.ComponentModel.Design namespace ArrayEditor class, 462 BinaryEditor class, 462 CollectionEditor class, 462, 464 CollectionEditor type editor, 919 ComponentDesigner class, 894 DesignerActionList class, 913 FontEditor class, 462 IDesigner interface, 893 ImageEditor class, 462 MultilineStringEditor class, 462 System.ComponentModel.Design.Serializati on namespace InstanceDescriptor class, 456 System.Drawing namespace, 49, 275, 284 Bitmap class, 151 Color structure, 52 Font class, 55 GDI+, 211 GDI+ graphics, 212 Graphics class, 213 Icon class, 152, 625 Image class, 151 importing, 52 Macdonald_4398Index.fm Page 1027 Sunday, November 20, 2005 5:15 PM ■I N D E X Pen class, 222 Region class, 815 SystemFonts class, 57 System.Drawing.Design namespace UITypeEditor class, 462, 464 System.Drawing.Drawing2D namespace GDI+ two-dimensional painting, 212 System.Drawing.Imaging namespace classes for manipulating bitmap and vector im, 212 Metafile class, 151 System.Drawing.Printing namespace rendering GDI+ content to the printer, 212 System.Drawing.Text namespace, 275 accessing currently installed fonts, 212 InstalledFontCollection class, 56 System.IO namespace DirectoryInfo class, 378 FileSystemWatcher class, 146 System.Media namespace SystemSounds class, 583 System.Reflection namespace ConstructorInfo class, 457 System.Text namespace StringBuilder class, 12 System.Text.RegularExpressions namespace Regex class, 628 System.Threading namespace Thread class, 354, 718 System.Web.UI namespace Web controls, System.Web.UI.Design.WebControls namespace RegexTypeEditor class, 462 System.Web.UI.HtmlControls namespace Web controls, System.Web.UI.WebControls namespace Web controls, System.Windows.Form.VisualStyles namespace, 261 System.Windows.Forms namespace BindingContext class, 288 Control class, 10, 44 CurrencyManager class, 288 DialogResult enumeration, 85 Form class, 15, 380, 382 Help class, 799 MenuStrip class, 477 StatusStrip class, 477 TextRenderer class, 233 Timer class, 696 ToolStrip class, 477 Windows controls, System.Windows.Forms.Design namespace ControlDesigner class, 894 FileNameEditor class, 463 FolderNameEditor class, 463 MaskPropertyEditor class, 463 ShortcutKeysEditor class, 463 ToolStripItemDesignerAvailability attribute, 507 TreeNodeCollectionEditor class, 464 System.Windows.Forms.Layout namespace DefaultLayout class, 748 FlowLayout class, 749 LayoutEngine class, 748 TableLayout class, 749 System.Windows.Forms.VisualStyles namespace enumerations, 258 VisualStyleElement nested classes, 258 VisualStyleInformation class, 258 VisualStyleRenderer class, 258 SystemBrushes class, 227 compared to SystemFont class, 57 SystemColors class, 52 compared to SystemFont class, 57 specifying a color, 52 SystemFont class compared to other classes dedicated to system settings, 57 SystemFonts class IconTitleFont property, 57 properties, 57 System.Drawing namespace, 57 SystemPens class, 222 compared to SystemFont class, 57 SystemSounds class Play() method, 583 properties, 583 System.Media namespace, 583 ■T tab order tool Visual Studio, 59 TabControl control, 134–135 properties, 135–136 1027 Macdonald_4398Index.fm Page 1028 Sunday, November 20, 2005 5:15 PM 1028 ■I N D E X TabCount property TabControl control, 136 TabIndex property controls, 59 Label control, 59 table of contents, creating, 795 Table property DataView class, 271 Table value ToolStripLayoutStyle enumeration, 479 TableCellFormattingEventArgs class, 550 TableLayout class System.Windows.Forms.Layout namespace, 749 TableLayoutPanel class, 749 Anchor property, 763, 764 AutoScroll property, 758, 766 AutoSize property, 762 CellBorderStyle property, 761 ColumnCount property, 759 ColumnStyles collection, 762, 764 Controls collection, 758 creating grid, 758 extended properties, 760 generating new rows and columns, 758–759 GrowStyle property, 758 layout panel examples bipane proportional resizing, 763 forms from a file, 766–775 list of settings, 764–766 localizable dialog box, 761–763 Padding property, 759 positioning controls, 759–760 properties, 755–756 row and column styles, 756–758 RowCount property, 759 RowStyles collection, 762 SizeMode property, 759 TableLayoutPanel control, 134 TableOfContents value HelpNavigator enumeration, 791 TabPage control ItemSize property, 136 properties, 136 TabPages collection, 136 TabPages collection TabPage control, 136 TabPages property TabControl control, 135 TabStop property controls, 59 Tag property Control class, 44, 313 ListView control, 175 ToolStripLabel class, 487 TreeNode class, 376 TreeView control, 195 TagName property HtmlElement object, 602 task queueing, 728–731 task-based Help, 800–802 TaskManager class, 728–731 TaskManagerClosing value CloseReason enumeration, 76 Testform.cs file, 29 Testform.Designer.cs file, 29 Text property Button control, 267 Control class, 55 DateTimePicker control, 132 DomainUpDown control, 127 Form class, 88 GroupBox control, 134 Label control, 112 list controls, 123, 124 ListItem class, 182 MaskedTextBox control, 644, 645 NotifyIcon component, 145 ProgressBar control, 896 TabPage control, 137 TextBox control, 267 ToolStripItem class, 484, 485 TextAboveImage value ToolStripItemDisplayStyle enumeration, 483 TextAlign property ToolStrip class, 485, 494 TextAndImage property ToolStripLabel class, 482 TextBeforeImage value ToolStripItemDisplayStyle enumeration, 482 TextBox control, 115, 116, 117 AutoComplete properties, 137 members, 115 Macdonald_4398Index.fm Page 1029 Sunday, November 20, 2005 5:15 PM ■I N D E X OnKeyPress() method, 20 Text property, 267 TextChanged event, 24, 624 Validating event, 620, 622 TextBoxBase class MaskedTextBox control derives from, 645 RichTextBox control derives from, 117 TextChanged event Control class, 629 Form class, 687 TextBox control, 24, 624 TextImageRelation property ToolStripItem class, 482, 485 TextMaskFormat property MaskedTextBox control, 645, 646 TextRenderer class DrawText() method, 233 MeasureText() method, 219, 233 System.Windows.Forms namespace, 233 using instead of Graphics.DrawString() method, 233 TextRenderingHint property Graphics class, 219, 221 TextureBrush class, 227, 231 Think() method AgentController class, 807 this keyword Visual Studio, 27 Thread class, 718 asynchronous programming, 696 creating a ThreadWrapper, 720–721 creating and tracking threads, 723–725 CurrentUICulture property, 168 methods, 719 properties, 719 Start() method, 696, 719, 721 System.Threading namespace, 354, 718 thread synchronization, 708 Control class, Invoke() method, 712 locking, 708 ThreadState property Thread class, 719 ThreadWrapper class creating, 720–721 improving, 726–727 ThreeDCheckBoxes property CheckedListBox control, 125 ThreeState property CheckBox control, 122 RadioButton control, 122 three-tier design in NET, 39 Tile view mode ListView control, 181 and large images, 181, 182 TileSize property ListView control, 181 Time data types data binding format string, 279 Timer class System.Windows.Forms namespace, 696 TitleBackColor property MonthCalendar control, 134 TitleForeColor property MonthCalendar control, 134 Today property DateTime class, 131 TodayDate property MonthCalendar control, 134 TodayDateSet property MonthCalendar control, 134 ToDisplayString() method MaskedTextProvider class, 650 Toggle() method Node class, 206 ToolBar class compared to ToolStrip class, 477 ToolStrip class adding sample items to, 885 as collection of ToolStripItem objects, 479–480 compared to MenuStrip, 501 creating a link, 486 creating toggle button, 486 dock padding, 101 embedding inside ToolStripContainer class, 487–489 events ItemClicked event, 512 Layout event, 510–512 LayoutCompleted event, 509, 510, 512 MouseDown event, 512 floating ToolStrip objects, 490–492 introduction, 477–479 Items collection, 485 1029 Macdonald_4398Index.fm Page 1030 Sunday, November 20, 2005 5:15 PM 1030 ■I N D E X menus, 496–498 context menus, 502–503 main menus, 500–501 multicolumn menus, 499–500 ToolStripMenuItem class, 497–498 properties AllowItemReorder property, 512 Dock property, 479 GripStyle property, 490 HasDropDownItems property, 510 ImageAlign property, 485 ImageOnly property, 482 ImageScalingSize property, 483 LayoutStyle property, 478 Opacity property, 499 OverflowButton property, 510 Renderer property, 514 RenderMode property, 514 ShowItemToolTips property, 484 Stretch property, 488, 500 TextAlign property, 485 ToolTipText property, 484 StatusStrip as subset of, 493 support for ToolStripItem classes, 493 support menu merging, 666 System.Windows.Forms namespace, 477 ToolStrip customization allowing runtime customization, 512–513 hosting other controls, 504–505 creating a custom ToolStripItem, 505–507 creating owner-drawn ToolStripItem, 508–509 design-time support for custom ToolStripItem, 507–508 introduction, 504 taking control of overflow menus, 509–512 ToolStrip example, 660–661 ToolStrip rendering customizing, 514–515 a renderer, 517–519 ToolStripManager, 515–517 ToolStripButton class Checked property, 486 CheckedChanged event, 486 CheckOnClick property, 486 container support, 493 derived from ToolStripItem class, 480 OnPaint() method, 508 ToolStripComboBox class container support, 493 ToolStripContainer class BottomToolStripPanelVisible property, 489 configuring panels, 490 ContentPanel property, 490 embedding ToolStrip inside, 487–489 lack of support for floating ToolStrip objects, 490 LeftToolStripPanelVisible property, 489 placing MenuStrip inside, 500 restricting, 489 RightToolStripPanelVisible property, 489 TopToolStripPanelVisible property, 489 ToolStripContentPanel class accessing, 490 Renderer property, 515 RenderMode property, 515 ToolStripControlHost class AutoSize property, 504 Control property, 505 derived from ToolStripItem class, 480 deriving a custom ToolStripItem from, 505 disadvantages to using, 505 DisplayStyle property not in, 482 hosting other controls in ToolStrip, 504 OnSubscribeControlEvents() method, 506 OnUnsubscribeControlEvents() method, 506 ToolStripDropDownButton class container support, 493 creating with three menus, 496 derived from ToolStripItem class, 480 ToolStripDropDownItem class creating drop-down menus, 496 derived from ToolStripItem class, 480 DropDown property, 499 DropDown.Renderer property, 514 DropDownDirection property, 496 events, 496 ToolStripMenuItem class derives from, 497 ToolStripDropDownMenu class ContextMenuStrip class derives from, 502 ToolStripDropDownMenuItem class ToolStripMenuItem class derives from, 501 ToolStripItem class creating a ToolStrip toggle button, 486 customizing, 505–507 Macdonald_4398Index.fm Page 1031 Sunday, November 20, 2005 5:15 PM ■I N D E X design-time support, 507–508 owner-drawn, 508–509 derived classes, 480 display styles, 482–483 events, 481–482 extending all classes deriving from, 880 full list of classes and container support, 493 images, 483 introduction, 479 methods OnPaint() method, 508 properties Alignment property, 485 AutoSize property, 485, 486 AutoToolTip property, 484 BackgroundImage property, 483 BackgroundImageLayout property, 483 DisplayStyle property, 482, 485 Image property, 483 ImageScaling property, 483 ImageTransparent property, 483 Margin property, 485 Overflow property, 509 Placement property, 510 Size property, 486 Text property, 484, 485 TextImageRelation property, 482, 485 size and alignment, 485, 486 ToolStripItemDesignerAvailability attribute, 509 System.Windows.Forms.Design namespace, 507 ToolStripItemDisplayStyle enumeration, 482 values, 482 ToolStripLabel class container support, 493 derived from ToolStripItem class, 480 properties IsLink property, 486 LinkBehavior property, 486 LinkColor property, 487 Tag property, 487 TextAndImage property, 482 VisitedLinkColor property, 487 ToolStripLayoutStyle enumeration values, 478, 486 c5b9fc1a45eb1e329bb0a9d79e858c51 ToolStripManager class, 737 introduction, 515–517 LoadSettings() method, 513 programmatic merging, 668 SaveSettings() method, 513 VisualStylesEnabled property, 519 ToolStripMenuItem class, 496 container support, 493 creating custom version, 503 DropDownClosed event, 664 DropDownItems collection, 501 DropDownOpening event, 664 introduction, 497, 498 lack of Clone() method, 503 objects in main menu, 501 ToolStripPanel class, 488 configuring panels, 490 Renderer property, 515 RenderMode property, 515 ToolStripProfessionalRenderer class, 515 changing colors, 519 deriving from ToolStripRenderer class, 514 ToolStripProgressBar class container support, 493 ToolStripRenderer class classes deriving from, 514 deriving from, 517 overridable methods, 517 ToolStripRenderMode enumeration values, 515 ToolStripSeparator class container support, 493 derived from ToolStripItem class, 480 DisplayStyle property not in, 482 ToolStripSplitButton class container support, 493 creating drop-down menus, 496 derived from ToolStripItem class, 480 ToolStripStatusLabel class container support, 493 customised version tailored for StatusStrip, 493 extends only ToolStripItem objects, 882 StatusStripHelpLabel class inherits from, 881 ToolStripSystemRenderer class deriving from ToolStripRenderer class, 514 1031 Macdonald_4398Index.fm Page 1032 Sunday, November 20, 2005 5:15 PM 1032 ■I N D E X ToolStripTextBox class container support, 493 ToolTip class extender providers, 143 members, 144–145 role of, 879 ToolTipIcon property ToolTip class, 145 ToolTipText property ListViewItem class, 181 TabPage control, 137 ToolStrip class, 484 ToolTipTitle property ToolTip class, 145 TopDown value FlowDirection enumeration, 751 topic pages, 793–794 Topic value HelpNavigator enumeration, 791 TopicId value HelpNavigator enumeration, 791 TopIndex property list controls, 124 TopLevelControl property controls, 46 TopMost property Form class, 74, 244 TopNode property TreeView control, 206 TopSizeable value SelectionRules enumeration, 903 TopToolStripPanel property ToolStripContainer class, 490 TopToolStripPanelVisible property ToolStripContainer class, 489 ToString() method FormattedListItemWrapper class, 392 TrackBar control, 128 TrailingForeColor property MonthCalendar control, 134 Transform() method GraphicsPath class, 235 TranslateTranform() method Graphics class, 240 transparency, 838 TransparencyKey property Form class, 75, 819–822 Transparent property Color structure, 55 TransparentColor property ImageList control, 155 TreeNode class deriving new node class from, 396 IsSelected property, 396 SelectedNode property, 396, 397 state properties, 204 Tag property, 376 TreeNodeCollection class methods, 201 TreeNodeCollectionEditor class System.Windows.Forms.Design namespace, 464 TreeView class adding features, 374 AfterSelect event, 314, 316 DirectoryTree Control derives from, 377 Nodes property, 896 TreeView control, 173 appearence properties, 204 custom colors and fonts, 396 drag-and-drop, 207–209 DrawMode property, 396 DrawNode event, 396 events, 202 expanding and collapsing levels, 206 flexible model for creating derived controls, 368–369 introduction, 195 manipulating nodes, 200–202 navigation, 197–199 properties, 199–200 node pictures, 205 Nodes collection, 896 Nodes property, 201 owner-drawn version, 396 custom MultiSelectTreeView control, 402–403 custom TreeNode, 396–398 drawing logic, 398–400 tracking selected nodes, 400–401 Remove() method, 200 SelectedNode property, 205 selecting nodes, 202–203 structure, 195–197 TreeView/ListView interface design, 943 Macdonald_4398Index.fm Page 1033 Sunday, November 20, 2005 5:15 PM ■I N D E X TreeViewCancelEventArgs object, 203 TreeViewEventArgs object, 203 TreeViewNodeSorter property TreeView control, 204 TriangleShape class, 858 Trimming property StringFormat class, 232 two-dimensional vector graphics GDI+, 212 Type class GetConstructor() method, 457 type converters applying to custom controls, 426 attaching, 451–452 creating, 448–451 creating a nested object with a constructor, 455–458 custom serialization with CodeDOM, 458 ExpandableObjectConverter class, 452–455 nested objects, 446–448 providing standard values, 458–461 System.ComponentModel namespace, 446 type editors, 461 applying to custom controls, 426 custom editors, 464 drop-down type editor, 468–471 modal type editor, 465–467 painting a thumbnail, 471–472 prebuilt type editors, 462–463 TypeConverter class adding attribute to custom class declaration, 451 GetStandardValues() method, 459 GetStandardValuesExclusive() method, 459 overridable methods, 449–450 System.ComponentModel namespace, 448 TypeDescriptor class CreateProperty() method, 898 GetConverter() method, 450 System.ComponentModel namespace, 896 TypeListConverter class CanConvertFrom() method, 919 types, introduction, 4, type-safe resources adding, 159–161 workings of, 161–164 TypeValidationCompleted event MaskedTextBox control, 647, 648 TypeValidationEventArgs class IsValidInput property, 647 typography GDI+, 212 ■U UITypeEditor class overridable methods, 464 System.Drawing.Design namespace, 462 UML diagrams defining interface for Progress user control, 342 unbound grids DataGridView class, 531, 532 Undo() method TextBox control, 116 Unified Modeling Language See UML UnInitialized value WebBrowserReadyState enumeration, 596 UnRegister() method HelpIconProvider class, 889 Update() method Control class, 217 DataAdapter class, 277 UpdateDisplay() method Bitmap Viewer user control, 348, 349, 353, 355 handling Click event, 351 Url property WebBrowser control, 594, 602 UsageMode property LicenseContext class, 934 UseAnimation property ToolTip class, 145 UseCompatibleTextRendering property Control class, 234 UseFading property ToolTip class, 145 UseMnemonic property Label control, 112 user controls, 337 bitmap thumbnail viewer, 344–355 compare to derived controls, 367–368 dynamic interfaces, 355–356 testing the wizard, 362 wizard controller, 359–361 wizard model, 356 wizard step, 357–358 introduction, 337 1033 Macdonald_4398Index.fm Page 1034 Sunday, November 20, 2005 5:15 PM 1034 ■I N D E X Progress user controls, 338–344 types of custom controls, 322 user interface architecture classes, and types, 4–5 role of, introduction, types classes, 5–6 delegates, 6–7 enumerations, 7–8 interfaces, structures, user interfaces brief history, 936 command-line era, 936–938 GUI era interfaces, 941–942 GUI interfaces, 940 menu-driven model interface, 940 question-answer model, 938–940 classes in NET, components, 18–19 controls accessing, 16–17 as classes, 9–10 containing other controls, 10–12 extending other controls, 12–14 creativity vs convention, 942 admistrative utilities, 943–944 application types, 944 consistency in NET, 942 Microsoft standards, 943 user requirements, 945 design, 935 approaches, 935–936 generating code in Visual studio, 25–27 handling complexity, 945 inductive user interfaces, 947 segmenting information, 946 helpful restrictions, 947 users choices, 948 users imagination, 949 users mistakes, 947 inheritance and the Form class, 14–15 interacting with controls, 19 overriding methods, 20 smart controls, 22 smart forms, 22–23 view-mediator pattern, 20–21 Visual studio, 23–25 application lifetime, 31–33 component tray, 27 hidden designer code, 28–30 UserAddedRow event DataGridView class, 560 UserClosing value CloseReason enumeration, 76 UserControl class base classes for custom controls, 323 UserControl control dock padding, 101 UserDeletedRow event DataGridView class, 560 UserDeletingRow event DataGridView class, 560 UserPreferenceChanged event, 57 UserSelection property Form class, 84 UseSystemPasswordChar property MaskedTextBox control, 646 TextBox control, 116 UseTabStops property list controls, 124 ■V Validate() method BaseValidator control, 634 LicenseManager class, 929, 930, 932 Validated event Control class, 618 validating validation events event sequence, 618 validating bound data, 294–296 Validating event Control class, 618 TextBox control, 620, 622 ValidatingType property MaskedTextBox control, 647 validation, 615 ASP.NET validation controls, 630 closing forms with, 620 custom validation components, 630 building the BaseValidator control, 631–635 building three custom validators, 635–638 Macdonald_4398Index.fm Page 1035 Sunday, November 20, 2005 5:15 PM ■I N D E X understanding ASP.NET validation controls, 630 using the custom validators, 638–641 DataGridView class, 563, 564, 565 ErrorProvider control, 621, 622 customizing error icons, 624–625 showing error icons, 622–624 regular expressions, 625–626 basics, 626–628 validating with, 628–629 validating at the right time, 615–616 validation events, 617 event sequence, 617–618 handling, 619–620 Value property DateTimePicker control, 130, 132 ProgressBar control, 339 TrackBar control, 128 Verbs property ControlDesigner class, 903 IDesigner interface, 894 versioning and interfaces, VerticalStackWithOverflow value ToolStripLayoutStyle enumeration, 478, 486 View property ListView control, 173, 177 view-mediator pattern, 20–21 virtualization ListView control, 189, 190, 191, 192, 194 VirtualListSize property ListView control, 192 VirtualMode property ListView control, 192 Visible property DataGridViewColumn class, 551 NotifyIcon component, 146 Visible value DesignerSerializationVisibility enumeration, 441, 458 SelectionRules enumeration, 903 Visited property Link object, 113 LinkLabel control, 114 VisitedLinkColor property LinkLabel control, 114 ToolStripLabel class, 487 Visual Basic Ruby, 41 Visual Studio adding ActiveX controls to projects, 148 aligning controls, 51 attaching keys, 335 automatic toolbox support, 330–331 automatically generated designer code, 76 ClickOnce, 954 Column and Row Styles dialog box, 757 Command Window, 937 configuring control properties and events, 23 creating a new form, 15 interaction between controls and form, 21 creating Program class in Windows projects, 87 custom controls support for, 426 GenerateMember property, 16 generating GradientFill object whenever properties are changed, 455 generating user interface code, 25–27 IconAlignment property, 625 IconPadding property, 625 Modifiers property, 16 Name property, 16 serialization rules, 437, 438 SetError() method, 625 tab order tool, 59 testing custom controls, 330 this keyword, 27 user interfaces, 23–25 application lifetime, 31–33 component tray, 27 hidden designer code, 28–30 Windows Application project, 23 Windows Control Library project, 23 VisualStyleElement class, 258 Menu classes, 259 VisualStyleInformation class IsEnabledByUser property, 258 IsSupportedByOS property, 258 System.Windows.Forms.VisualStyles namespace, 258 1035 Macdonald_4398Index.fm Page 1036 Sunday, November 20, 2005 5:15 PM 1036 ■I N D E X VisualStyleRenderer class, 255 drawing, 258–259 IsElementDefined() method, 259 methods, 259, 261 System.Windows.Forms.VisualStyles namespace, 258 uses Windows XP themes, 414 VisualStylesEnabled property ToolStripManager class, 516, 519 VisualStyleState property Application class, 258 VScroll property Form class, 82 ■W Warp() method GraphicsPath class, 235 WAV audio format supported by SoundPlayer control, 580 Web controls System.Web.UI namespace, System.Web.UI.HtmlControls namespace, System.Web.UI.WebControls namespace, WebBrowser control basics, 593 blending Web and Windows interfaces, 601 building a DOM tree, 601–604 extracting all links, 604–606 scripting a Web page, 606–609 scripting an HTML form, 610–611 Document property, 601 Document.InvokeScript() method, 609 DocumentStream property, 594, 602 DocumentText property, 594, 602 events, 596–597 example, 597–599 IsBusy property, 596 methods, 600 Navigate() method, 595, 602 navigating to a page, 594–595 navigation methods, 595 ObjectForScripting property, 606 printing, saving and fine tuning, 599–600 properties, 600 ReadyState property, 596 Url property, 594, 602 uses, 593 WebBrowserReadyState enumeration values, 596 WebBrowserShortcutsEnabled property WebBrowser control, 600 WebWorks Publisher Help authoring tools, 787 WFC limitations, 41 WFML markup-based user interfaces, 779 Widen() method GraphicsPath class, 235 Width property CountStyle class, 757 DataGridViewColumn class, 543 Pens class, 223 Size object, 49 Win32 functions GetWindowPlacement() function, 80 SetWindowPlacement() function, 80 WindowListChanged event DocumentManager class, 689 WindowListChangedEventArgs class, 687 Windows Application project, 23 Windows applications multithreading, 700–712 Windows Control Library custom controls, 326 Windows Control Library project, 23 Windows controls System.Windows.Forms namespace, Windows Forms introduction, 41–42 Windows Forms application design, 33 developing in tiers, 36–37 business tier, 38 data tier, 38–39 presentation tier, 37 three-tier design in NET, 39 encapsulation, 33 control references, 35 data-driven user interfaces, 35 using central switchboard, 34 using collections, 35 using enumerations and helper classes, 35 Macdonald_4398Index.fm Page 1037 Sunday, November 20, 2005 5:15 PM ■I N D E X Windows Forms architecture user interface classes plug into, Windows controls, Windows Forms controls owner drawing and, 389 Windows Forms Markup Language See WFML Windows Media Audio See WMA Windows XP styles, 47 WindowsDefaultBound value FormStartPosition enumeration, 77 WindowsDefaultLocation value FormStartPosition enumeration, 77 WindowsShutDown value CloseReason enumeration, 76 WindowState property Form class, 74 WinHelp, 783 choices supported, 791 WinHelp 95, 784 choices supported, 791 Winres.exe, 171 Wizard class ShowStep() method, 359, 360 wizards question-answer model interface, 938 WMA files not supported by SoundPlayer control, 580 playing with Quartz, 584 WndProc() method Control class, 70, 654 Form class, 587, 821 WordWrap property TextBox control, 117 worker component, 701, 702 WorkerSupportsCancellation property BackgroundWorker component, 716 WorkingArea property Screen class, 78 WrapContents property FlowLayoutPanel class, 751, 753, 754 FlowLayoutPanel control, 355 WrapMode property DataGridViewCellStyle class, 548 ■X XAML markup-based user interfaces, 779 ■Z ZoomFactor property RichTextBox control, 119 ZOrder property Shape class, 862, 863 1037 Macdonald_4398Index.fm Page 1038 Sunday, November 20, 2005 5:15 PM c5b9fc1a45eb1e329bb0a9d79e858c51 Macdonald_4398Index.fm Page 1039 Sunday, November 20, 2005 5:15 PM Macdonald_4398Index.fm Page 1040 Sunday, November 20, 2005 5:15 PM forums.apress.com FOR PROFESSIONALS BY PROFESSIONALS™ JOIN THE APRESS FORUMS AND BE PART OF OUR COMMUNITY You’ll find discussions that cover topics of interest to IT professionals, programmers, and enthusiasts just like you If you post a query to one of our forums, you can expect that some of the best minds in the business—especially Apress authors, who all write with The Expert’s Voice™—will chime in to help you Why not aim to become one of our most valuable participants (MVPs) and win cool stuff? Here’s a sampling of what you’ll find: DATABASES PROGRAMMING/BUSINESS Data drives everything Share information, exchange ideas, and discuss any database programming or administration issues Unfortunately, it is Talk about the Apress line of books that cover software methodology, best practices, and how programmers interact with the “suits.” INTERNET TECHNOLOGIES AND NETWORKING WEB DEVELOPMENT/DESIGN Try living without plumbing (and eventually IPv6) Talk about networking topics including protocols, design, administration, wireless, wired, storage, backup, certifications, trends, and new technologies Ugly doesn’t cut it anymore, and CGI is absurd Help is in sight for your site Find design solutions for your projects and get ideas for building an interactive Web site JAVA SECURITY We’ve come a long way from the old Oak tree Hang out and discuss Java in whatever flavor you choose: J2SE, J2EE, J2ME, Jakarta, and so on Lots of bad guys out there—the good guys need help Discuss computer and network security issues here Just don’t let anyone else know the answers! MAC OS X TECHNOLOGY IN ACTION All about the Zen of OS X OS X is both the present and the future for Mac apps Make suggestions, offer up ideas, or boast about your new hardware Cool things Fun things It’s after hours It’s time to play Whether you’re into LEGO® MINDSTORMS™ or turning an old PC into a DVR, this is where technology turns into fun OPEN SOURCE WINDOWS Source code is good; understanding (open) source is better Discuss open source technologies and related topics such as PHP, MySQL, Linux, Perl, Apache, Python, and more No defenestration here Ask questions about all aspects of Windows programming, get help on Microsoft technologies covered in Apress books, or provide feedback on any Apress Windows book HOW TO PARTICIPATE: Go to the Apress Forums site at http://forums.apress.com/ Click the New User link ... PM Pro NET 2.0 Windows Forms and Custom Controls in C# ■■■ Matthew MacDonald Macdonald_4398Front.fm Page ii Friday, November 18, 2005 5:14 PM Pro NET 2.0 Windows Forms and Custom Controls in C#. .. programming journals, and the author of more than a dozen books about NET programming, including User Interfaces in C#: Windows Forms and Custom Controls (Apress), Pro ASP.NET 2.0 (Apress), and. .. docs, Pro NET 2.0 Windows Forms and Custom Controls does an excellent job of filtering the information down to what developers really need to harness the power and innovations of Windows Forms 2.0

Ngày đăng: 19/10/2013, 21:15

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan