1. Trang chủ
  2. » Công Nghệ Thông Tin

Pro NET windows forms and custom

1,1K 95 0

Đ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

Thông tin cơ bản

Định dạng
Số trang 1.077
Dung lượng 22,89 MB

Nội dung

CYAN MAGENTA YELLOW BLACK PANTONE 123 CV BOOKS FOR PROFESSIONALS BY PROFESSIONALS ® THE EXPERT’S VOICE ® IN NET Companion eBook Available Pro NET 2.0 Windows Forms and Custom Controls in VB 2005 User Interfaces in VB NET (Apress) User Interfaces in C# (Apress) The Book of VB 2005 Microsoft NET Distributed Applications Pro NET 2.0 Windows Forms and Custom Controls in C# Join online discussions: Matthew MacDonald (Microsoft MVP in Client Development, MCSD) forums.apress.com FOR PROFESSIONALS BY PROFESSIONALS ™ THE APRESS ROADMAP Pro VB 2005 and the NET 2.0 Platform Companion eBook An Introduction to Object-Oriented Programming with Visual Basic NET Visual Basic NET Class Design Handbook Pro NET 2.0 Windows Forms And Custom Controls In VB 2005 Data Entry and Validation with C# and VB.NET Windows Forms See last page for details on $10 eBook version ISBN 1-59059-694-3 SOURCE CODE ONLINE Controls in VB 2005 Microsoft Visual Basic NET Programmer’s Cookbook NET 2.0 Windows Forms Author of When the NET Framework first appeared, many assumed it would usher in a new world of web-only programming Today, four years after the initial release of NET 1.0, Windows applications refuse to die—in fact, they’re thriving With NET 2.0, Microsoft has rediscovered Windows applications You’ll find long-requested features, like a flexible web-like layout model, the ability to display HTML pages, and support for Windows XP visual styles Entirely new controls fill major gaps, like the modern ToolStrip and the high-powered DataGridView There’s even a whole new deployment system, called ClickOnce, that offers streamlined installations from a web page and automatic updates In short, NET 2.0 has everything you need to build modern Windows applications In this book, you’ll explore the Windows Forms toolkit in detail and learn how to create everything from a vector-drawing program to a document-view framework Best of all, you’ll learn how to take your applications to the next step by extending the NET Framework For example, you’ll learn how to design over a dozen custom controls that handle everything from Wizard systems to skinned buttons And when you discover some of the real limitations that still exist in NET—like its meager sound support—you’ll find out how you can solve the problem with other components If you’re looking for the most thorough book about Windows Forms user interfaces, welcome aboard! and Custom Dear Reader, Pro 54999 www.apress.com MacDonald US $49.99 Shelve in Programming/ Microsoft/.NET 89253 59694 Pro NET 2.0 Windows Forms and Custom Controls in VB 2005 Create modern user interfaces for Windows applications Matthew MacDonald Foreword by Shawn Burke Development Manager, Windows Forms Team, Microsoft Corporation 781590 596944 User level: Intermediate–Advanced this print for content only—size & color not accurate spine = 1.851" 1,800 page count Macdonald_694-3FRONT.fm Page i Friday, July 28, 2006 6:48 AM Pro NET 2.0 Windows Forms and Custom Controls in VB 2005 ■■■ Matthew MacDonald Macdonald_694-3FRONT.fm Page ii Friday, July 28, 2006 6:48 AM Pro NET 2.0 Windows Forms and Custom Controls in VB 2005 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-13 (pbk): 978-1-59059-694-4 ISBN-10 (pbk): 1-59059-694-3 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: Jonathan Gennick Technical Reviewer: Manish Jayaswal Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick, Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser, Keir Thomas, Matt Wade Project Manager: Elizabeth Seymour Copy Edit Manager: Nicole LeClerc Copy Editor: Heather Lang Assistant Production Director: Kari Brooks-Copony Senior Production Editor: Laura Cheu Compositor: Susan Glinert Stevens Proofreader: Liz Berry Indexer: Michael Brinkman Artist: April Milne 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_694-3FRONT.fm Page iii Friday, July 28, 2006 6:48 AM For Hamid and Razia Macdonald_694-3FRONT.fm Page iv Friday, July 28, 2006 6:48 AM Macdonald_694-3FRONT.fm Page v Friday, July 28, 2006 6:48 AM 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 71 ■CHAPTER The Classic Controls 109 ■CHAPTER Images and Resources 151 ■CHAPTER Lists and Trees 173 ■CHAPTER Drawing with GDI+ 209 ■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 v Macdonald_694-3FRONT.fm Page vi Friday, July 28, 2006 6:48 AM PART ■■■ Modern Controls ■CHAPTER 14 Tool, Menu, and Status Strips 477 ■CHAPTER 15 The DataGridView 519 ■CHAPTER 16 Sound and Video 577 ■CHAPTER 17 The WebBrowser 589 PART ■■■ Windows Forms Techniques ■CHAPTER 18 Validation and Masked Editing 611 ■CHAPTER 19 Multiple and Single Document Interfaces 651 ■CHAPTER 20 Multithreading 689 ■CHAPTER 21 Dynamic Interfaces and Layout Engines 729 ■CHAPTER 22 Help Systems 777 PART ■■■ Advanced Custom Controls ■CHAPTER 23 Skinned Forms and Animated Buttons 811 ■CHAPTER 24 Dynamic Drawing with a Design Surface 839 ■CHAPTER 25 Custom Extender Providers 871 ■CHAPTER 26 Advanced Design-Time Support 885 ■APPENDIX A Creating Usable Interfaces 927 ■APPENDIX B ClickOnce 943 ■INDEX 963 vi Macdonald_694-3FRONT.fm Page vii Friday, July 28, 2006 6:48 AM 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 Controls Can Extend Other Controls 12 Inheritance and the Form Class 13 Accessing Controls 15 Components 17 Interacting with a Control 19 Overriding Methods 19 The View-Mediator Pattern 20 Smart Controls 21 Smart Forms 22 Visual Studio 22 Generating User-Interface Code in Visual Studio 24 The Component Tray 26 The Hidden Designer Code 27 The Application Framework 30 Designing Windows Forms Applications 34 Encapsulation 34 Developing in Tiers 37 The Last Word 40 vii Macdonald_694-3FRONT.fm Page viii Friday, July 28, 2006 6:48 AM 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 46 Position and Size 48 Overlapping Controls 50 Color 52 Alpha Blending 55 Fonts and Text 56 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 65 A Mouse/Keyboard Example 67 Mouse Cursors 68 Low-Level Members 69 The Last Word 70 ■CHAPTER Forms 71 The Form Class 71 Form Size and Position 74 Scrollable Forms 79 Showing a Form 81 Custom Dialog Windows 81 Form Interaction 84 Form Ownership 88 Prebuilt Dialogs 90 Resizable Forms 93 The Problem of Size 94 Minimum and Maximum Form Size 95 Anchoring 95 Docking 99 Autosizing 100 Macdonald_694-3FRONT.fm Page ix Friday, July 28, 2006 6:48 AM ■C O N T E N T S Splitting Windows 103 Building Split Windows with Panels 105 Other Split Windows 106 The Last Word 108 ■CHAPTER The Classic Controls 109 The Classic Control Gallery 109 Labels 109 LinkLabel 110 Button 112 TextBox 113 RichTextBox 115 CheckBox and RadioButton 120 PictureBox 121 List Controls 121 Other Domain Controls 125 The Date Controls 127 The DateTimePicker 128 MonthCalendar 130 Container Controls 132 The TabControl 133 AutoComplete 135 Drag-and-Drop 137 “Fake” Drag-and-Drop 137 Authentic Drag-and-Drop 138 Extender Providers 141 The NotifyIcon 144 ActiveX Controls 147 Should You Import ActiveX Controls? 148 The Last Word 149 ■CHAPTER Images and Resources 151 The Image Class 151 Common Controls and Images 152 The ImageList 155 Resources 158 Adding a Type-Safe Resource 159 How Type-Safe Resources Work 161 Form Resources 163 Creating Additional Resource Files 165 ix Macdonald_694-3INDEX.fm Page 1022 Friday, July 28, 2006 4:36 AM 1022 ■I N D E X Size property Control class, 49, 843 Form class, 74 Shape class, 849 ToolStripItem class, 486 Size structure properties, 49 returned by MeasureString() method, Graphics class, 218 SizeChanged event Form class, 95 SizeGripStyle property Form class, 72, 217 SizeMode property TabControl control, 134 TableLayoutPanel class, 755 SizeMode value PictureBoxSizeMode enumeration, 121 SizeType enumeration Percent value, 760 values, 753 SizeType property CountStyle class, 753 RowStyle class, 753 skinned interfaces, 811 SkipLiterals property MaskedTextBox control, 643 Sleep() method Thread class, 714 SmallCaptionFont property SystemFonts class, 57 SmallIcon value View enumeration, 174 SmallIcon view mode ListView control, 175 SmallImageList property ListView control, 174, 176 smart controls, 21–22 smart forms, 22 smart tags, 885, 904, 905 action list, 905–907 control designer, 910 DesignerActionItem class, 908, 909 workings of, 24 SmoothingMode property Graphics class, 217, 220 social security number regular expression, 624 SolidBrush class, 226 Sort property DataView class, 271 Sort() method DataGridView class, 535 ListView control, 184 Sorted property list controls, 122 Sorter property TreeView control, 203 sorting ListView control, 182–186 Sorting property ListView control, 177 SortMode property DataGridViewColumn class, 535 sound and video advanced media with DirectShow, 581 SoundPlayer control, 577–581 sound files embedding into compiled assemblies, 580 SoundLocation property SoundPlayer control, 578 SoundLocationChanged event SoundPlayer control, 578 SoundPlayer control events, 578 introduction, 577, 578 load and play sound asynchronously, 579–580 load and play sound synchronously, 578 methods, 578 PlaySound() function, 577 properties, 578 System.Media namespace, 577 SystemSounds class, 580 SourceControl property ContextMenu control, 846 ContextMenuStrip class, 502 Control class, 796 Macdonald_694-3INDEX.fm Page 1023 Friday, July 28, 2006 4:36 AM ■I N D E X StartupNextInstance event application framework, 31 State property AnimatedButtonBase class, 821 stationary embedded application-embedded support, 800 status bar creating, 493–495 StatusFont property SystemFonts class, 57 StatusStrip class, 492 creating a status bar, 493–495 support for ToolStripItem classes, 492 System.Windows.Forms namespace, 477 ToolStrip class is basis of, 477 StatusStripHelpLabel provider changing how extended properties appear, 877 choosing a base class, 873 choosing control to extend, 873–874 implementing GetXxx() and SetXxx() methods, 875–876 providing the extended property, 874–875 testing the provider, 877 StatusTextChanged event WebBrowser control, 593 Step property ProgressBar control, 339 Step() method ProgressBar control, 127 Stop() method IMediaControl interface, 582 SoundPlayer control, 578 WebBrowser control, 591 stream objects supported by SoundPlayer control, 577 Stream property SoundPlayer control, 578 StreamChanged event SoundPlayer control, 578 Stretch property ToolStrip class, 488, 499 StringBuilder class System.Text namespace, 12 StringFormat class properties, 231 Find it faster at http://superindex.apress.com Speak() method AgentController class, 804 specific-length password regular expressions, 623 SplitContainer class Dock property, 104 members, 103–104 SplitContainer control, 132 dock padding, 100 SplitterDistance property SplitContainer class, 104 SplitterIncrement property SplitContainer class, 104 SplitterMoved event SplitContainer class, 104 SplitterMoving event SplitContainer class, 104 splitting windows, 103–104 building with Panels, 105 other split windows, 106–107 spreadsheets not provided in DataGridView, 521 Spring property customised version of ToolStripStatusLabel class, 493–494 StackWithOverflow value ToolStripLayoutStyle enumeration, 478, 486 StandardTab property DataGridView class, 524 Start property LinkLabel control, 112 Start() method Thread class, 692, 713, 714, 716 StartCap property Pens class, 222 StartFigure() method GraphicsPath class, 234, 253 StartLoadingImages() method Bitmap Viewer user control, 355 StartPosition property Form class, 74 Startup event application framework, 31 1023 Macdonald_694-3INDEX.fm Page 1024 Friday, July 28, 2006 4:36 AM 1024 ■I N D E X structures, introduction, Style property DataGridViewCell class, 543 StyleName property AnimatedButtonBase class, 838 Sunken value Border3DStyle enumeration, 494 SunkenInner value Border3DStyle enumeration, 494 SunkenOuter value Border3DStyle enumeration, 494 SupportsChangeNotification property IBindingList interface, 300 SupportsSearching property IBindingList interface, 301 SupportsSorting property IBindingList interface, 301 SuppressKeyPress property KeyPressEventArgs class, 64 SuspendLayout() method collection-based Windows Forms controls, 347 container controls, 412 designer-generated code, 381 SyncLock statement, 715 system fonts, 57 System namespace DateTime class, 129 System value ToolStripRenderMode enumeration, 513 System.Collection namespace IComparer interface, 182 System.Collections.Generic namespace Dictionary collection, 87 List collection, 87 System.ComponentModel namespace attributes, 428–429 attributes for control properties, 438 BackgroundWorker component, 707 BindingList(Of T) collection, 301 Component class, 18, 324, 627, 878 DefaultValueAttribute class, 439 IComponent interface, 17, 324 IExtenderProvider interface, 873 importing, 327 License class, 920 LicenseProvider class, 920 MaskedTextProvider class, 646 ProvideProperty attribute, 873 type converters, 447 TypeConverter class, 449 TypeDescriptor class, 888 System.ComponentModel.Design namespace ArrayEditor class, 463 BinaryEditor class, 463 CollectionEditor class, 463, 465 CollectionEditor type editor, 911 ComponentDesigner class, 886 DesignerActionList class, 905 FontEditor class, 463 IDesigner interface, 885 ImageEditor class, 463 MultilineStringEditor class, 463 System.ComponentModel.Design Serialization namespace InstanceDescriptor class, 457 System.Data.SqlClient namespace importing, 268 System.Drawing namespace, 49, 275, 283 Bitmap class, 151 Color structure, 52 Font class, 56 GDI+, 209, 210 Graphics class, 211 Icon class, 152, 621 Image class, 151 importing, 52, 327 Pen class, 221 Region class, 811 SystemFonts class, 57 System.Drawing.Design namespace UITypeEditor class, 463, 465 System.Drawing.Drawing2D namespace GDI+ two-dimensional painting, 210 System.Drawing.Imaging namespace classes for manipulating bitmap and vectors, 210 Metafile class, 151 System.Drawing.Printing namespace rendering GDI+ content to the printer, 210 Macdonald_694-3INDEX.fm Page 1025 Friday, July 28, 2006 4:36 AM ■I N D E X System.Windows.Forms.Design namespace ControlDesigner class, 886 FileNameEditor class, 464 FolderNameEditor class, 464 MaskPropertyEditor class, 464 ShortcutKeysEditor class, 464 ToolStripItemDesignerAvailability attribute, 506 TreeNodeCollectionEditor class, 465 System.Windows.Forms.Layout namespace DefaultLayout class, 744 FlowLayout class, 744 LayoutEngine class, 744 TableLayout class, 744 System.Windows.Forms.VisualStyles namespace, 260 enumerations, 257 VisualStyleElement nested classes, 257 VisualStyleInformation class, 257 VisualStyleRenderer class, 257 SystemBrushes class, 226 compared to SystemFont class, 57 SystemColors class, 52 compared to SystemFont class, 57 specifying a color, 52 SystemFont class, 57 SystemFonts class, 57 SystemPens class, 221 compared to SystemFont class, 57 SystemSound class System.Media namespace, 577 SystemSounds class based on the MessageBeep Win32 API, 580 Play() method, 581 properties, 581 System.Media namespace, 577, 580 ■T tab order tool Visual Studio, 59 TabControl control, 132–133 properties, 134 TabCount property TabControl control, 134 Find it faster at http://superindex.apress.com System.Drawing.Text namespace, 275 accessing currently installed fonts, 210 InstalledFontCollection class, 56 System.Globalization namespace CultureInfo class, 168 System.IO namespace DirectoryInfo class, 378 FileSystemWatcher class, 144 System.Media namespace SoundPlayer class, 577 SystemSound class, 577 SystemSounds class, 577, 580 System.Reflection namespace ConstructorInfo class, 458 System.Text namespace StringBuilder class, 12 System.Text.RegularExpressions namespace Regex class, 624 System.Threading namespace Thread class, 355, 713 System.Web.UI namespace Web controls, System.Web.UI.Design.WebControls namespace RegexTypeEditor class, 464 System.Web.UI.HtmlControls namespace Web controls, System.Web.UI.WebControls namespace Web controls, System.Windows.Forms namespace BindingContext class, 286 Control class, 9, 44 CurrencyManager class, 286 DialogResult enumeration, 83 Form class, 13, 15, 22, 380, 382 Help class, 795 importing, 327 MenuStrip class, 477 StatusStrip class, 477 TextRenderer class, 232 Timer class, 692 ToolStrip class, 477 Windows controls, 1025 Macdonald_694-3INDEX.fm Page 1026 Friday, July 28, 2006 4:36 AM 1026 ■I N D E X TabIndex property controls, 59 Label control, 59 table of contents, creating for HTML Help, 791–792 Table property DataView class, 271 Table value ToolStripLayoutStyle enumeration, 478 TableCellFormattingEventArgs class, 547 TableLayout class System.Windows.Forms.Layout namespace, 744 TableLayoutPanel class, 744 Anchor property, 759, 760 AutoScroll property, 754, 762 AutoSize property, 759 CellBorderStyle property, 757 ColumnCount property, 755 ColumnStyles collection, 758, 760, 761 Controls collection, 754 creating grid, 754 extended properties, 756 generating new rows and columns, 754, 755 GrowStyle property, 754 layout panel examples bipane proportional resizing, 759–760 forms from a file, 762–771 list of settings, 760–762 localizable dialog box, 757–759 Padding property, 755 positioning controls, 755–756 properties, 751–752 row and column styles, 752–754 RowCount property, 755 RowStyles collection, 758 SizeMode property, 755 TableLayoutPanel control, 132 TableOfContents value HelpNavigator enumeration, 788 TabPage control ItemSize property, 134 properties, 134 TabPages collection, 134 TabPages collection TabPage control, 134 TabPages property TabControl control, 133 TabStop property controls, 59 Tag property Control class, 44, 312 ListView control, 175 ToolStripLabel class, 486 TreeNode class, 376 TreeView control, 194 TagName property HtmlElement object, 598 task queueing, 723–727 task-based Help, 797–799 TaskManager class, 723–727 TaskManagerClosing value CloseReason enumeration, 74 Testform.cs file, 27, 28 Testform.Designer.cs file, 27, 28 Text property Button control, 266 Control class, 56 DateTimePicker control, 130 DomainUpDown control, 125 Form class, 88 GroupBox control, 132 Label control, 110 list controls, 121, 122 ListItem class, 182 MaskedTextBox control, 640, 641 NotifyIcon component, 144 ProgressBar control, 888 TabPage control, 135 TextBox control, 266 ToolStripItem class, 479, 483, 484 TextAboveImage value ToolStripItemDisplayStyle enumeration, 482 TextAlign property ToolStrip class, 485, 494 TextAndImage property ToolStripLabel class, 482 Macdonald_694-3INDEX.fm Page 1027 Friday, July 28, 2006 4:36 AM ■I N D E X System.Threading namespace, 355, 713 task queueing, 723–727 thread starvation, 723 thread synchronization, 714 Control class, Invoke() method, 706 locking, 715 ThreadState property Thread class, 714 ThreadWrapper class creating, 716–717 improving, 721–723 ThreeDCheckBoxes property CheckedListBox control, 123 ThreeState property CheckBox control, 120 RadioButton control, 120 three-tier design, 37, 40 thumbnails, painting, 473 Tile value View enumeration, 174 Tile view mode ListView control, 180 and large images, 181 TileSize property ListView control, 180 Time data types data binding format string, 279 Timer class System.Windows.Forms namespace, 692 TitleBackColor property MonthCalendar control, 132 TitleForeColor property MonthCalendar control, 132 Today property DateTime class, 129 TodayDate property MonthCalendar control, 132 TodayDateSet property MonthCalendar control, 132 ToDisplayString() method MaskedTextProvider class, 647 Toggle() method Node class, 204 ToolBar class compared to ToolStrip class, 477 Find it faster at http://superindex.apress.com TextBeforeImage value ToolStripItemDisplayStyle enumeration, 482 TextBox class extending, 327 TextBox control, 113, 114, 115 AutoComplete properties, 135 members, 114 OnKeyPress() method, 19 Text property, 266 TextChanged event, 23, 619 Validating event, 615, 618 TextBoxBase class MaskedTextBox control derives from, 641 RichTextBox control derives from, 116 TextChanged event Control class, 624 Form class, 682 TextBox control, 23, 619 TextImageRelation property ToolStripItem class, 482, 485 TextMaskFormat property MaskedTextBox control, 641, 642 TextRenderer class DrawText() method, 232 MeasureText() method, 218, 232 System.Windows.Forms namespace, 232 using instead of Graphics.DrawString() method, 232 TextRenderingHint property Graphics class, 217, 220 TextureBrush class, 226 Think() method AgentController class, 804 third-party controls, 322 Thread class, 712, 713 asynchronous programming, 692 creating a ThreadWrapper, 716–717 creating and tracking threads, 719–720 creating derived Task class, 717–719 CurrentUICulture property, 167 locking and synchronization, 714–715 methods, 714 properties, 713 Start() method, 692, 713, 716 1027 Macdonald_694-3INDEX.fm Page 1028 Friday, July 28, 2006 4:36 AM 1028 ■I N D E X toolbox icon, adding, 431, 432, 433 ToolStrip class adding sample items to, 877 adding with Visual Studio designer, 480 AllowItemReorder property, 511 as collection of ToolStripItem objects, 479 compared to MenuStrip, 499 creating a link, 486 creating toggle button, 486 customizing, 512–513 a renderer, 515–517 ToolStripManager, 513–515 dock padding, 100 embedding inside ToolStripContainer class, 487–489 example, 656–657 floating ToolStrip objects, 490–491 GripStyle property, 489 HasDropDownItems property, 508 ImageAlign property, 485 ImageOnly property, 482 ImageScalingSize property, 483 introduction, 477–479 ItemClicked event, 511 Items collection, 485 Layout event, 509, 510 LayoutCompleted event, 508, 509, 510 LayoutStyle property, 478 menus, 495, 496, 497 context menus, 501–502 main menus, 499–500 multicolumn menus, 498–499 ToolStripMenuItem class, 496–497 MergeAction property, 664 MergeIndex property, 664 MouseDown event, 511 Opacity property, 498 OverflowButton property, 508 Renderer property, 512 RenderMode property, 513 ShowItemToolTips property, 483 StatusStrip as subset of, 493 Stretch property, 488, 499 support for ToolStripItem classes, 492 support menu merging, 662 System.Windows.Forms namespace, 477 TextAlign property, 485 ToolTipText property, 483 ToolStrip customization allowing runtime customization, 510–511 hosting other controls, 503–504 creating a custom ToolStripItem, 504–506 creating owner-drawn ToolStripItem, 507–508 design-time support for custom ToolStripItem, 506–507 introduction, 502 taking control of overflow menus, 508–510 ToolStripButton class Checked property, 486 CheckedChanged event, 486 CheckOnClick property, 486 container support, 492 derived from ToolStripItem class, 479 OnPaint() method, 507 ToolStripComboBox class container support, 492 ToolStripContainer class BottomToolStripPanelVisible property, 489 configuring panels, 489 ContentPanel property, 490 embedding ToolStrip inside, 487–489 lack of support for floating ToolStrip objects, 490 LeftToolStripPanelVisible property, 489 placing MenuStrip inside, 499 restricting, 489 RightToolStripPanelVisible property, 489 TopToolStripPanelVisible property, 489 ToolStripContentPanel class accessing, 490 Renderer property, 513 RenderMode property, 513 ToolStripControlHost class AutoSize property, 503 Control property, 504 derived from ToolStripItem class, 480 deriving a custom ToolStripItem from, 504 disadvantages to using, 504 Macdonald_694-3INDEX.fm Page 1029 Friday, July 28, 2006 4:36 AM ■I N D E X size and alignment, 484–486 Size property, 486 Text property, 483, 484 TextImageRelation property, 482, 485 ToolStripItem control extending all classes deriving from, 872 ToolStripItemDesignerAvailability attribute, 507 System.Windows.Forms.Design namespace, 506 ToolStripItemDisplayStyle enumeration, 482 values, 482 ToolStripLabel class container support, 492 derived from ToolStripItem class, 479 IsLink property, 486 LinkBehavior property, 486 LinkColor property, 486 Tag property, 486 TextAndImage property, 482 VisitedLinkColor property, 486 ToolStripLayoutStyle enumeration values, 478, 486 ToolStripManager class, 733 introduction, 513–515 LoadSettings() method, 511 Merge() method, 731 programmatic merging, 664 SaveSettings() method, 511 VisualStylesEnabled property, 517 ToolStripMenuItem class, 495 container support, 492 creating custom version, 502 DropDownClosed event, 660 DropDownItems collection, 500 DropDownOpening event, 660 introduction, 496–497 lack of Clone() method, 502 objects in main menu, 500 Visible property, 663 ToolStripPanel class, 488 configuring panels, 489 Renderer property, 513 RenderMode property, 513 Find it faster at http://superindex.apress.com DisplayStyle property not in, 482 hosting other controls in ToolStrip, 503 ToolStripDropDownButton class container support, 492 creating with three menus, 495 derived from ToolStripItem class, 480 ToolStripDropDownItem class creating drop-down menus, 495 derived from ToolStripItem class, 480 DropDown property, 498 DropDown.Renderer property, 512 DropDownDirection property, 495 events, 495 ToolStripMenuItem class derives from, 496 ToolStripDropDownMenu class ContextMenuStrip class derives from, 501 ToolStripDropDownMenuItem class ToolStripMenuItem class derives from, 500 ToolStripItem class Alignment property, 485 AutoSize property, 485, 486 AutoToolTip property, 483 BackgroundImage property, 483 BackgroundImageLayout property, 483 creating a ToolStrip toggle button, 486 customizing, 504–506 design-time support, 506–507 owner-drawn, 507–508 derived classes, 479 display styles, 482–483 DisplayStyle property, 484 events, 481 full list of classes and container support, 492 Image property, 483 images, 483 ImageScaling property, 483 ImageTransparent property, 483 introduction, 479 Margin property, 484 OnPaint() method, 507 Overflow property, 508 Placement property, 508 1029 Macdonald_694-3INDEX.fm Page 1030 Friday, July 28, 2006 4:36 AM 1030 ■I N D E X ToolStripProfessionalRenderer class, 513 changing colors, 517 deriving from ToolStripRenderer class, 512 ToolStripProgressBar class container support, 493 ToolStripRenderer class classes deriving from, 512 deriving from, 515 overridable methods, 515 ToolStripRenderMode enumeration values, 513 ToolStripSeparator class container support, 492 derived from ToolStripItem class, 480 DisplayStyle property not in, 482 ToolStripSplitButton class container support, 492 creating drop-down menus, 495 derived from ToolStripItem class, 480 ToolStripStatusLabel class container support, 493 customised version tailored for StatusStrip, 493 extends only ToolStripItem objects, 874 StatusStripHelpLabel class inherits from, 873 ToolStripSystemRenderer class deriving from ToolStripRenderer class, 512 ToolStripTextBox class container support, 492 ToolTip class extender providers for component, 141 members, 142–143 role of, 871 ToolTipIcon property ToolTip class, 143 ToolTipText property ListViewItem class, 180 TabPage control, 135 ToolStrip class, 483 ToolTipTitle property ToolTip class, 143 TopDown value FlowDirection enumeration, 747 topic pages, 790 Topic value HelpNavigator enumeration, 788 TopicId value HelpNavigator enumeration, 788 TopIndex property list controls, 122 TopLevelControl property controls, 46 TopMost property Form class, 72, 243 TopNode property TreeView control, 205 TopSizeable value SelectionRules enumeration, 895 TopToolStripPanel property ToolStripContainer class, 489 TopToolStripPanelVisible property ToolStripContainer class, 489 ToString() method FormattedListItemWrapper class, 393 TrackBar control, 126 TrailingForeColor property MonthCalendar control, 132 Transform() method GraphicsPath class, 234 TranslateTranform() method Graphics class, 239 transparency, 833 TransparencyKey property Form class, 73, 815, 816, 818 Transparent property Color structure, 55 TransparentColor property ImageList control, 155 TreeNode class deriving custom class, 376 deriving new node class from, 396 IsSelected property, 396 SelectedNode property, 396, 397 state properties, 203 Tag property, 376 TreeNodeCollection class methods, 199 TreeNodeCollectionEditor class System.Windows.Forms.Design namespace, 465 Macdonald_694-3INDEX.fm Page 1031 Friday, July 28, 2006 4:36 AM ■I N D E X type converters applying to custom controls, 426 attaching, 452–453 creating, 449–452 creating a nested object with a constructor, 457–459 custom serialization with CodeDOM, 459 ExpandableObjectConverter class, 454–457 nested objects, 447–449 providing standard values, 459–462 System.ComponentModel namespace, 447 type editors, 462–463 applying to custom controls, 426 custom editors, 465 drop-down type editor, 469–472 modal type editor, 466–468 painting a thumbnail, 473 prebuilt type editors, 463–464 TypeConverter class adding attribute to custom class declaration, 452 GetStandardValues() method, 460 GetStandardValuesExclusive() method, 461 overridable methods, 450, 451 System.ComponentModel namespace, 449 TypeDescriptor class CreateProperty() method, 890 GetConverter() method, 451 System.ComponentModel namespace, 888 TypeListConverter class CanConvertFrom() method, 911 TypeOf keyword, 88 types, introduction, 4, type-safe resources adding, 159–161 workings of, 161–163 TypeValidationCompleted event MaskedTextBox control, 643, 644 TypeValidationEventArgs class IsValidInput property, 643 typography, GDI+, 210 Find it faster at http://superindex.apress.com TreeView control, 173 adding features, 375 AfterSelect event, 313, 316, 375 appearence properties, 202 BeforeExpand event, 315 custom colors and fonts, 396 DirectoryTree Control derives from, 377 drag-and-drop, 205–208 DrawMode property, 396 DrawNode event, 396 example with just-in-time nodes, 314–317 expanding and collapsing levels, 204–205 flexible model for creating derived controls, 368–369 ImageList property, 371 introduction, 193–194 manipulating nodes, 199–200 navigation, 196–197 properties, 197–198 node events, 200 node pictures, 203 Nodes collection, 888 Nodes property, 199, 888 OnAfterSelect() event, 375 owner-drawn version, 396 custom MultiSelectTreeView control, 402–403 custom TreeNode, 396–398 drawing logic, 398–400 tracking selected nodes, 400–401 Remove() method, 199 SelectedNode property, 203 selecting nodes, 200–202 structure, 194–195 TreeView/ListView interface design, 935 TreeViewCancelEventArgs object, 201 TreeViewEventArgs object, 201 TreeViewNodeSorter property TreeView control, 203 TriangleShape class, 851 Trimming property StringFormat class, 231 two-dimensional vector graphics, GDI+, 210 Type class GetConstructor() method, 458 1031 Macdonald_694-3INDEX.fm Page 1032 Friday, July 28, 2006 4:36 AM 1032 ■I N D E X ■U UITypeEditor class overridable methods, 465 System.Drawing.Design namespace, 463 UML diagrams defining interface for Progress user control, 342 unbound data, displaying with DataGridView control, 553 unbound grids DataGridView class, 528–530 Undo() method TextBox control, 114 UnhandledException event application framework, 31 Unified Modeling Language, 342 UnInitialized value WebBrowserReadyState enumeration, 592 UnRegister() method HelpIconProvider class, 881 UnSelect() method MultiSelectTreeNode control, 400 Update() method Control class, 215 DataAdapter class, 277 UpdateDisplay() method Bitmap Viewer user control, 349, 350, 352, 354, 356 Url property WebBrowser control, 590, 597 UsageMode property LicenseContext class, 925 UseAnimation property ToolTip class, 143 UseCompatibleTextRendering property Control class, 233 UseFading property ToolTip class, 143 UseMnemonic property Label control, 110 user controls, 337 bitmap thumbnail viewer, 345–356 compared to derived controls, 367–368 dynamic interfaces, 356 testing the wizard, 363 wizard controller, 360–362 wizard model, 357 wizard step, 358–359 introduction, 337 Progress user controls, 338–344 types of custom controls, 322 user interface architecture classes and objects, classes and types, 4–5 classes, 5–6 delegates, 6–7 enumerations, 7–8 interfaces, structures, introduction, types and structures, user interfaces application framework, 30 disabling, 32–33 events, 31–32 brief history, 928 command-line era, 929–930 GUI era interfaces, 933–934 GUI interfaces, 932 menu-driven model interface, 932 question-answer model, 930–932 classes in NET, components, 17–18 controls accessing, 15–16 as classes, containing other controls, 9–11 extending other controls, 12–13 creativity vs convention, 934 admistrative utilities, 935–936 application types, 936 consistency in NET, 934 Microsoft standards, 935 user requirements, 937 design, 927 approaches, 928 generating code in Visual studio, 24, 26 handling complexity, 937 inductive user interfaces, 939 IUI (inductive user interfaces), 939 segmenting information, 938 Macdonald_694-3INDEX.fm Page 1033 Friday, July 28, 2006 4:36 AM ■I N D E X ■V Validate() method BaseValidator control, 627, 630 LicenseManager class, 920, 922, 924 Validating event Control class, 614, 627 TextBox control, 615, 618 ValidatingType property MaskedTextBox control, 643 validation, 611 ASP.NET validation controls, 626 bound data, 293–294 closing forms with, 616, 617 custom validation components, 625 building the BaseValidator control, 627–631 building three custom validators, 631–634 understanding ASP.NET validation controls, 626 using the custom validators, 634–637 DataGridView class, 560–562 ErrorProvider control, 617 customizing error icons, 619–620 showing error icons, 618–619 regular expressions, 621 basics, 621–624 bvalidating with, 624 validating with, 625 validating at the right time, 611–612 validation events, 613 event sequence, 613–614 handling, 615–616 Value property DateTimePicker control, 128, 130 Progress control, 472 ProgressBar control, 339 TrackBar control, 126 vector-based drawing programs, 839 Verbs property ControlDesigner class, 895 IDesigner interface, 886 versioning, interfaces and, VerticalStackWithOverflow value ToolStripLayoutStyle enumeration, 478, 486 View enumeration values, 173 View property ListView control, 173, 177 Find it faster at http://superindex.apress.com helpful restrictions, 939 users choices, 940 users imagination, 941 users mistakes, 939 inheritance and the Form class, 13–15 interacting with controls, 19 overriding methods, 19 smart controls, 21–22 smart forms, 22 view-mediator pattern, 20–21 Visual studio, 22–24 application lifetime, 34 component tray, 26 hidden designer code, 27–29 User32.dll library GetKeyState() function, 63 UserAddedRow event DataGridView class, 557 UserClosing value CloseReason enumeration, 74 UserControl class all user control classes derive from, 339 base classes for custom controls, 323 benefits of using, 339 OrderPrintPreview and OrderGridView derive from, 667 UserControl control dock padding, 100 UserDeletedRow event DataGridView class, 557 UserDeletingRow event DataGridView class, 557 UserPreferenceChanged event, 58 UserSelection property Form class, 82 UseSystemPasswordChar property MaskedTextBox control, 642 TextBox control, 115 UseTabStops property list controls, 122 1033 Macdonald_694-3INDEX.fm Page 1034 Friday, July 28, 2006 4:36 AM 1034 ■I N D E X view-mediator pattern, 20–21 virtualization and ListView control, 189–193 VirtualListSize property ListView control, 191 VirtualMode property ListView control, 191 Visible property DataGridViewColumn class, 548 NotifyIcon component, 144 ToolStripItem class, 479 ToolStripMenuItem class, 663 Visible value DesignerSerializationVisibility enumeration, 442, 459 SelectionRules enumeration, 895 Visited property Link object, 111 LinkLabel control, 112 VisitedLinkColor property LinkLabel control, 112 ToolStripLabel class, 486 Visual Basic partial classes, 27 Resources.resx file, 161 Ruby, 41 Visual Studio adding ActiveX controls to projects, 147 aligning controls, 51 application framework, 30 disabling, 32–33 events, 31–32 attaching keys, 335 automatic toolbox support, 330 automatically generated designer code, 74 ClickOnce, 946 Column and Row Styles dialog box, 753 Command Window, 929 configuring control properties and events, 23 creating a new form, 14 interaction between controls and form, 20 custom controls support, 426 Form.Localizable property added at design time, 166 GenerateMember property, 15 generating GradientFill object whenever properties are changed, 456 generating user interface code, 24, 26 IconAlignment property, 620 IconPadding property, 620 Me keyword, 26 Modifiers property, 15 Name property, 16 serialization rules, 437–438 SetError() method, 620 tab order tool, 59, 60 testing custom controls, 330 user interfaces, 22–24 application lifetime, 34 component tray, 26 hidden designer code, 27–29 Windows Application project, 22 Windows Control Library project, 22 VisualStyleElement class, 257 Menu classes, 258 VisualStyleInformation class IsEnabledByUser property, 257 IsSupportedByOS property, 257 System.Windows.Forms.VisualStyles namespace, 257 VisualStyleRenderer class, 255 drawing, 258 IsElementDefined() method, 258 methods, 258, 260 System.Windows.Forms.VisualStyles namespace, 257 uses Windows XP themes, 414 VisualStylesEnabled property ToolStripManager class, 514, 517 VisualStyleState property Application class, 257 VScroll property Form class, 80 ■W WaitOnLoad property image-related properties in common controls, 154 Warp() method GraphicsPath class, 234 Macdonald_694-3INDEX.fm Page 1035 Friday, July 28, 2006 4:36 AM ■I N D E X Width property CountStyle class, 753 DataGridViewColumn class, 540 Pens class, 222 Size object, 49 Win32 functions GetWindowPlacement() function, 78 SetWindowPlacement() function, 78 WindowListChanged event DocumentManager class, 684 WindowListChangedEventArgs class, 683 Windows Application project, 22 Windows applications multithreading, 696–706 Windows Control Library custom controls, 326 Windows Control Library project, 22 Windows controls painting, 254 ControlPaint class, 255, 256 using a control renderer, 260, 261 visual styles, 256–257 VisualStyleRenderer class, 258, 259, 260 System.Windows.Forms namespace, Windows Forms introduction, 41, 42 Windows Forms application design, 34 developing in tiers, 37, 38 business tier, 39 data tier, 39–40 presentation tier, 38 three-tier design in NET, 40 encapsulation, 34 control references, 36 data-driven user interfaces, 36 using central switchboard, 35 using collections, 36 using enumerations and helper classes, 36 Windows Forms architecture user interface classes plug into, Windows controls, Windows Forms controls owner drawing and, 389 Find it faster at http://superindex.apress.com WAV audio format supported by SoundPlayer control, 578 Web controls System.Web.UI namespace, System.Web.UI.HtmlControls namespace, System.Web.UI.WebControls namespace, web pages as online Help, 787 WebBrowser control basics, 589 blending Web and Windows interfaces, 597 building a DOM tree, 597–599 extracting all links, 600–602 scripting a Web page, 602–604 scripting an HTML form, 605–606 Document property, 597 Document.InvokeScript() method, 604 DocumentStream property, 590, 597 DocumentText property, 590, 597 events, 592–593 example, 593–595 IsBusy property, 592 methods, 596 Navigate() method, 591, 597 Navigating event, 607 navigating to a page, 590–591 navigation methods, 591 ObjectForScripting property, 602 printing, saving and fine tuning, 595–596 properties, 595 ReadyState property, 592 Url property, 590, 597 uses, 589 WebBrowserReadyState enumeration values, 592 WebBrowserShortcutsEnabled property WebBrowser control, 596 WebWorks Publisher Help authoring tools, 783 WFC limitations, 41 WFML, markup-based user interfaces, 774 Widen() method GraphicsPath class, 234 1035 Macdonald_694-3INDEX.fm Page 1036 Friday, July 28, 2006 4:36 AM 1036 ■I N D E X Windows Forms Markup Language See WFML Windows Media Audio See WMA Windows XP styles, 46 WindowsDefaultBound value FormStartPosition enumeration, 75 WindowsDefaultLocation value FormStartPosition enumeration, 75 WindowsShutDown value CloseReason enumeration, 74 WindowState property Form class, 72 WinHelp, 779 choices supported, 788 WinHelp 95, 780 choices supported, 788 Winres.exe, 170 Wizard class ShowDialog() method, 363 ShowStep() method, 360, 361 wizard model creating Wixard controller form, 360–362 defining interface, 358–359 introduction, 357 testing, 363 wizards question-answer model interface, 930 reasons for using dynamic interfaces, 730 WMA files not supported by SoundPlayer control, 578 playing with Quartz, 582 WndProc() method Control class, 70, 650 Form class, 585, 818 WordWrap property TextBox control, 115 Worker component, 697, 698 FindPrimes() method, 697, 699, 708, 709 WorkerSupportsCancellation property BackgroundWorker component, 711 WorkingArea property Screen class, 76 Workplace applications as MDI application type, 652 WrapContents property FlowLayoutPanel class, 747, 749, 750 FlowLayoutPanel control, 356 WrapMode property DataGridViewCellStyle class, 545 ■X XAML markup-based user interfaces, 774 ■Z ZoomFactor property RichTextBox control, 117 ZOrder property Shape class, 856, 857 ... 2006 6:48 AM Pro NET 2.0 Windows Forms and Custom Controls in VB 2005 ■■■ Matthew MacDonald Macdonald_694-3FRONT.fm Page ii Friday, July 28, 2006 6:48 AM Pro NET 2.0 Windows Forms and Custom Controls... skinned custom controls, this book shows you how The practical, task-based approach of Pro NET 2.0 Windows Forms and Custom Controls in VB 2005 allows the book to cover a wide range of Windows Forms. .. technology that is appropriate for the task at hand, which means they can implement their vision without compromising the user experience Version 1.0 of Windows Forms and the NET Framework were

Ngày đăng: 26/03/2019, 09:57

TỪ KHÓA LIÊN QUAN