Tải bản đầy đủ (.pdf) (1,251 trang)

visual basic 2008 programmer's reference

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (15.69 MB, 1,251 trang )

Visual Basic® 2008
Programmer’s Reference
Rod Stephens
Wiley Publishing, Inc.
ffirs.indd iiiffirs.indd iii 12/19/07 3:18:12 PM12/19/07 3:18:12 PM

Part I: IDE
Chapter 1: Introduction to
the IDE . . . . . . . . . . . . . . . . . . . . . . 3
Chapter 2: Menus, Toolbars,
and Windows . . . . . . . . . . . . . . . . . 15
Chapter 3: Customization . . . . . . . 43
Chapter 4: Windows Form
Designer . . . . . . . . . . . . . . . . . . . . 49
Chapter 5: WPF Designer . . . . . . . . 61
Chapter 6: Visual Basic
Code Editor . . . . . . . . . . . . . . . . . . 71
Chapter 7: Debugging . . . . . . . . . . 87
Part II: Getting Started
Chapter 8: Selecting Windows
Forms Controls . . . . . . . . . . . . . . 103
Chapter 9: Using Windows
Forms Controls . . . . . . . . . . . . . . 121
Chapter 10: Windows Forms . . . . . 149
Chapter 11: Selecting WPF
Controls . . . . . . . . . . . . . . . . . . . 175
Chapter 12: Using WPF Controls . 187
Chapter 13: WPF Windows . . . . . 223
Chapter 14: Program and
Module Structure . . . . . . . . . . . . 237


Chapter 15: Data Types,
Variables, and Constants . . . . . . . 261
Chapter 16: Operators . . . . . . . . . 307
Chapter 17: Subroutines and
Functions . . . . . . . . . . . . . . . . . . 327
Chapter 18: Program Control
Statements . . . . . . . . . . . . . . . . . 353
Chapter 19: Error Handling . . . . . .377
Chapter 20: Database Controls
and Objects . . . . . . . . . . . . . . . . . 401
Chapter 21: LINQ . . . . . . . . . . . . . 457
Chapter 22: Custom Controls . . . . 493
Chapter 23: Drag and Drop,
and the Clipboard . . . . . . . . . . . . 519
Chapter 24: UAC Security . . . . . . 537
Part III: Object-Oriented
Programming
Chapter 25: OOP Concepts . . . . . 547
Chapter 26: Classes and
Structures . . . . . . . . . . . . . . . . . . 563
Chapter 27: Namespaces . . . . . . . 605
Chapter 28: Collection Classes . . 619
Chapter 29: Generics . . . . . . . . . . 647
Part IV: Graphics
Chapter 30: Drawing Basics . . . . . 661
Chapter 31: Brushes, Pens,
and Paths . . . . . . . . . . . . . . . . . . 697
Chapter 32: Text . . . . . . . . . . . . . 727
Chapter 33: Image
Processing . . . . . . . . . . . . . . . . . 745

Chapter 34: Printing . . . . . . . . . . 761
Chapter 35: Reporting . . . . . . . . . 781
Visual Basic® 2008
Programmer’s Reference
(Continued)
ffirs.indd iffirs.indd i 12/19/07 3:18:11 PM12/19/07 3:18:11 PM
Part V: Interacting with the
Environment
Chapter 36: Configuration and
Resources . . . . . . . . . . . . . . . . . . 805
Chapter 37: Streams . . . . . . . . . . 837
Chapter 38: File-System
Objects . . . . . . . . . . . . . . . . . . . . 849
Chapter 39: Windows
Communication Foundation . . . . . 873
Chapter 40: Useful Namespaces . 885
Part VI: Appendices
Appendix A: Useful Control
Properties, Methods,
and Events . . . . . . . . . . . . . . . . . 911
Appendix B: Variable
Declarations and Data Types . . . . 923
Appendix C: Operators . . . . . . . . . 931
Appendix D: Subroutine
and Function Declarations . . . . . . 939
Appendix E: Control Statements. . 943
Appendix F: Error Handling . . . . . . 949
Appendix G: Windows Forms
Controls and Components . . . . . . 951
Appendix H: WPF Controls . . . . . 1035

Appendix I: Visual Basic
Power Packs . . . . . . . . . . . . . . . 1043
Appendix J: Form Objects . . . . . . 1047
Appendix K: Classes and
Structures . . . . . . . . . . . . . . . . . 1063
Appendix L: LINQ . . . . . . . . . . . . 1067
Appendix M: Generics . . . . . . . . 1077
Appendix N: Graphics . . . . . . . . 1081
Appendix O: Useful Exception
Classes . . . . . . . . . . . . . . . . . . . 1095
Appendix P: Date and Time
Format Specifiers . . . . . . . . . . . 1099
Appendix Q: Other Format
Specifiers . . . . . . . . . . . . . . . . . 1103
Appendix R: The Application
Class . . . . . . . . . . . . . . . . . . . . 1109
Appendix S: The My
Namespace . . . . . . . . . . . . . . . . 1113
Appendix T: Streams . . . . . . . . . 1131
Appendix U: File-System
Classes . . . . . . . . . . . . . . . . . . . 1139
Appendix V: Index of
Examples . . . . . . . . . . . . . . . . . 1157
Index . . . . . . . . . . . . . . . . . . . . 1177
ffirs.indd iiffirs.indd ii 12/19/07 3:18:12 PM12/19/07 3:18:12 PM
Visual Basic® 2008
Programmer’s Reference
Rod Stephens
Wiley Publishing, Inc.
ffirs.indd iiiffirs.indd iii 12/19/07 3:18:12 PM12/19/07 3:18:12 PM

Visual Basic® 2008 Programmer’s Reference
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2008 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-18262-8
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
Library of Congress Cataloging-in-Publication Data is available from Publisher.
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by
any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted
under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written
permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the
Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600.
Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing,
Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at
/>Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or
warranties with respect to the accuracy or completeness of the contents of this work and specifically
disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No
warranty may be created or extended by sales or promotional materials. The advice and strategies contained
herein may not be suitable for every situation. This work is sold with the understanding that the publisher is
not engaged in rendering legal, accounting, or other professional services. If professional assistance is
required, the services of a competent professional person should be sought. Neither the publisher nor the
author shall be liable for damages arising herefrom. The fact that an organization or Website is referred to in
this work as a citation and/or a potential source of further information does not mean that the author or the
publisher endorses the information the organization or Website may provide or recommendations it may
make. Further, readers should be aware that Internet Websites listed in this work may have changed or

disappeared between when this work was written and when it is read.
For general information on our other products and services please contact our Customer Care Department
within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related
trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the
United States and other countries, and may not be used without written permission. Visual Basic is a
registered trademark of Microsoft Corporation in the United States and/or other countries. All other
trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any
product or vendor mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not
be available in electronic books.
ffirs.indd ivffirs.indd iv 12/19/07 3:18:12 PM12/19/07 3:18:12 PM
About the Author
Rod Stephens started out as a mathematician, but while studying at MIT, discovered the joys of
programming and has been programming professionally ever since. During his career, he has worked on
an eclectic assortment of applications in such fields as telephone switching, billing, repair dispatching,
tax processing, wastewater treatment, concert ticket sales, cartography, and training for professional
football players.
Rod is a Microsoft Visual Basic Most Valuable Professional (MVP) and ITT adjunct instructor. He has
written 18 books that have been translated into half a dozen different languages, and more than 200
magazine articles covering Visual Basic, Visual Basic for Applications, Delphi, and Java. He is currently a
regular contributor to DevX (
www.DevX.com ).
Rod ’ s popular VB Helper web site
www.vb-helper.com receives several million hits per month and
contains thousands of pages of tips, tricks, and example code for Visual Basic programmers, as well as
example code for this book.
Credits
Executive Editor
Robert Elliott

Development Editor
Christopher J. Rivera
Technical Editor
John Mueller
Production Editor
Angela Smith
Copy Editor
Kim Cofer
Editorial Manager
Mary Beth Wakefield
Production Manager
Tim Tate
Vice President and Executive Group Publisher
Richard Swadley
Vice President and Executive Publisher
Joseph B. Wikert
Project Coordinator, Cover
Lynsey Stanford
Proofreader
Nancy Hanger, Windhaven
Indexer
J & J Indexing
ffirs.indd vffirs.indd v 12/19/07 3:18:12 PM12/19/07 3:18:12 PM
Acknowledgments
Thanks to Bob Elliott, Christopher Rivera, Angela Smith, and all of the others who work so hard to make
producing any book possible.
Thanks also to technical editor John Mueller for adding extra depth and perspective to the book. Visit

www.mwt.net/~jmueller to learn about John ’ s books and to sign up for his free newsletter .NET Tips,
Trends & Technology eXTRA .

ffirs.indd viffirs.indd vi 12/19/07 3:18:13 PM12/19/07 3:18:13 PM
Contents
Acknowledgments vi
Introduction xxvii
Part I: IDE 1
Chapter 1: Introduction to the IDE 3
Different IDE Appearance 4
IDE Configurations 5
Projects and Solutions 6
Starting the IDE 7
Creating a Project 9
Saving a Project 12
Summary 13
Chapter 2: Menus, Toolbars, and Windows 15
Menus 15
File 16
Edit 18
View 20
Project 21
Build 26
Debug 28
Data 28
Format 28
Tools 29
Test 33
Window 34
Community 35
Help 35
Toolbars 35
Secondary Windows 36

Toolbox 37
Properties Window 38
Summary 41
ftoc.indd viiftoc.indd vii 12/19/07 3:17:02 PM12/19/07 3:17:02 PM
Contents
viii
Chapter 3: Customization 43
Adding Commands 43
Removing Commands 45
Modifying Commands 45
Making Keyboard Shortcuts 47
Summary 48
Chapter 4: Windows Form Designer 49
Setting Designer Options 49
Adding Controls 51
Selecting Controls 51
Copying Controls 53
Moving and Sizing Controls 54
Arranging Controls 54
Setting Properties 54
Setting Group Properties 55
Setting Properties for Several Controls 55
Using Smart Tags 56
Using Command Verbs 56
Adding Code to Controls 57
Summary 59
Chapter 5: WPF Designer 61
Early Version Warning 61
Recognizing Designer Windows 63
Adding Controls 64

Selecting Controls 64
Copying Controls 65
Moving and Sizing Controls 66
Setting Properties 67
Setting Group Properties 68
Adding Code to Controls 68
Summary 69
Chapter 6: Visual Basic Code Editor 71
Margin Icons 72
Outlining 74
Tooltips 75
IntelliSense 77
ftoc.indd viiiftoc.indd viii 12/19/07 3:17:02 PM12/19/07 3:17:02 PM
Contents
ix
Code Coloring and Highlighting 79
Code Snippets 81
Using Snippets 82
Creating Snippets 83
The Code Editor at Runtime 85
Summary 86
Chapter 7: Debugging 87
The Debug Menu 87
The Debug Windows Submenu 91
The Breakpoints Window 95
The Command and Immediate Windows 97
Summary 99
Part II: Getting Started 101
Chapter 8: Selecting Windows Forms Controls 103
Controls Overview 103

Choosing Controls 109
Containing and Arranging Controls 109
Making Selections 111
Entering Data 113
Displaying Data 113
Providing Feedback 114
Initiating Action 115
Displaying Graphics 116
Displaying Dialog Boxes 117
Supporting Other Controls 117
Third-Party Controls 118
Summary 119
Chapter 9: Using Windows Forms Controls 121
Controls and Components 121
Creating Controls 123
Creating Controls at Design Time 123
Adding Controls to Containers 124
Creating Controls at Runtime 124
Properties 126
Properties at Design Time 127
Properties at Runtime 132
ftoc.indd ixftoc.indd ix 12/19/07 3:17:02 PM12/19/07 3:17:02 PM
Contents
x
Useful Control Properties 133
Position and Size Properties 137
Methods 138
Events 139
Creating Event Handlers at Design Time 139
WithEvents Event Handlers 141

Setting Event Handlers at Runtime 141
Control Array Events 142
Validation Events 143
Summary 147
Chapter 10: Windows Forms 149
Transparency 150
About, Splash, and Login Forms 153
Mouse Cursors 154
Icons 156
Application Icons 157
Notification Icons 157
Properties Adopted by Child Controls 158
Property Reset Methods 159
Overriding WndProc 159
SDI and MDI 161
MDI Features 162
MDI Events 165
MDI versus SDI 167
MRU Lists 168
Dialog Boxes 170
Wizards 172
Summary 173
Chapter 11: Selecting WPF Controls 175
Controls Overview 176
Containing and Arranging Controls 176
Making Selections 179
Entering Data 180
Displaying Data 180
Providing Feedback 181
Initiating Action 182

Presenting Graphics and Media 182
Providing Navigation 184
Managing Documents 184
ftoc.indd xftoc.indd x 12/19/07 3:17:03 PM12/19/07 3:17:03 PM
Contents
xi
Digital Ink 184
Summary 185
Chapter 12: Using WPF Controls 187
WPF Concepts 187
Separation of User Interface and Code 188
WPF Control Hierarchies 189
WPF in the IDE 190
Editing XAML 190
Editing Visual Basic Code 194
XAML Features 197
Objects 197
Resources 199
Styles 201
Templates 202
Transformations 205
Animations 206
Drawing Objects 208
Procedural WPF 213
Documents 218
Flow Documents 218
Fixed Documents 221
XPS Documents 221
Summary 222
Chapter 13: WPF Windows 223

Window Applications 223
Page Applications 225
Browser Applications 226
Frame Applications 227
PageFunction Applications 229
Wizard Applications 231
Summary 235
Chapter 14: Program and Module Structure 237
Hidden Files 237
Code File Structure 242
Code Regions 243
Conditional Compilation 243
Namespaces 252
ftoc.indd xiftoc.indd xi 12/19/07 3:17:03 PM12/19/07 3:17:03 PM
Contents
xii
Typographic Code Elements 253
Comments 253
XML Comments 254
Line Continuation 258
Line Joining 259
Line Labels 259
Summary 260
Chapter 15: Data Types, Variables, and Constants 261
Data Types 262
Type Characters 264
Data Type Conversion 266
Narrowing Conversions 267
Data Type Parsing Methods 269
Widening Conversions 269

Variable Declarations 270
Attribute_List 270
Accessibility 271
Shared 272
Shadows 272
ReadOnly 274
Dim 275
WithEvents 276
Name 278
Bounds_List 279
New 280
As Type and Inferred Types 280
Initialization_Expression 281
Multiple Variable Declarations 285
Option Explicit and Option Strict 286
Scope 288
Block Scope 288
Procedure Scope 290
Module Scope 290
Namespace Scope 291
Restricting Scope 291
Parameter Declarations 292
Property Procedures 294
Enumerated Data Types 295
Anonymous Types 298
Nullable Types 299
ftoc.indd xiiftoc.indd xii 12/19/07 3:17:03 PM12/19/07 3:17:03 PM
Contents
xiii
Constants 300

Accessibility 300
As Type 301
Initialization_Expression 301
Delegates 302
Naming Conventions 303
Summary 305
Chapter 16: Operators 307
Arithmetic Operators 307
Concatenation Operators 308
Comparison Operators 309
Logical Operators 311
Bitwise Operators 312
Operator Precedence 313
Assignment Operators 314
The StringBuilder Class 316
Date and TimeSpan Operations 318
Operator Overloading 321
Operators with Nullable Types 324
Summary 324
Chapter 17: Subroutines and Functions 327
Subroutines 327
Attribute_List 328
Inheritance_Mode 332
Accessibility 333
Subroutine_Name 334
Parameters 334
Implements interface.subroutine 341
Statements 342
Functions 343
Property Procedures 344

Extension Methods 344
Lambda Functions 346
Relaxed Delegates 347
Partial Methods 350
Summary 352
ftoc.indd xiiiftoc.indd xiii 12/19/07 3:17:03 PM12/19/07 3:17:03 PM
Contents
xiv
Chapter 18: Program Control Statements 353
Decision Statements 353
Single Line If Then 353
Multiline If Then 355
Select Case 355
Enumerated Values 358
IIf 359
If 360
Choose 360
Looping Statements 362
For Next 362
Non-integer For Next Loops 364
For Each 365
Enumerators 367
Iterators 369
Do Loop Statements 369
While End 371
Exit and Continue 371
GoTo 372
Summary 375
Chapter 19: Error Handling 377
Bugs versus Unplanned Conditions 377

Catching Bugs 378
Catching Unexpected Conditions 380
Global Exception Handling 382
Structured Error Handling 383
Exception Objects 385
StackTrace Objects 386
Throwing Exceptions 387
Custom Exceptions 389
Visual Basic Classic Error Handling 391
On Error GoTo Line 391
On Error Resume Next 392
On Error GoTo 0 393
On Error GoTo Ϫ1 394
Error-Handling Mode 395
Structured versus Classic Error Handling 396
The Err Object 397
Debugging 398
Summary 399
ftoc.indd xivftoc.indd xiv 12/19/07 3:17:04 PM12/19/07 3:17:04 PM
Contents
xv
Chapter 20: Database Controls and Objects 401
Automatically Connecting to Data 401
Connecting to the Data Source 402
Adding Data Controls to the Form 406
Automatically Created Objects 410
Other Data Objects 412
Data Overview 413
Connection Objects 414
Transaction Objects 417

Data Adapters 419
Command Objects 424
DataSet 426
DataTable 430
DataRow 433
DataColumn 435
DataRelation 437
Constraints 440
DataView 442
DataRowView 445
Simple Data Binding 446
CurrencyManager 448
Complex Data Binding 451
Summary 455
Chapter 21: LINQ 457
Introduction to LINQ 458
Basic LINQ Query Syntax 460
From 460
Where 461
Order By 462
Select 462
Using LINQ Results 465
Advanced LINQ Query Syntax 466
Join 466
Group By 467
Aggregate Functions 470
Set Operations 471
Limiting Results 471
LINQ Functions 472
ftoc.indd xvftoc.indd xv 12/19/07 3:17:04 PM12/19/07 3:17:04 PM

Contents
xvi
LINQ Extension Methods 474
Method-Based Queries 474
Method-Based Queries with Lambda Functions 476
Extending LINQ 477
LINQ to Objects 480
LINQ to XML 481
XML Literals 481
LINQ Into XML 482
LINQ Out Of XML 484
LINQ to ADO.NET 487
LINQ to SQL and LINQ to Entities 487
LINQ to DataSet 488
Summary 491
Chapter 22: Custom Controls 493
Custom Controls in General 494
Creating the Control Project 494
Setting the Toolbox Icon 495
Testing in the UserControl Test Container 495
Making a Test Project 496
Test the Control 498
Implement Properties, Methods, and Events 498
Assign Attributes 499
Manage Design Time and Runtime 501
Derived Controls 502
Shadowing Parent Features 504
Hiding Parent Features 505
Composite Controls 506
Controls Built from Scratch 508

Components 509
Invisible Controls 510
Picking a Control Class 511
Controls and Components in Executable Projects 512
UserControls in Executable Projects 512
Inherited UserControls in Executable Projects 512
Controls in Executable Projects 513
Inherited Controls in Executable Projects 513
Components in Executable Projects 514
Custom Component Security 514
Strongly Named Assemblies 514
Using a Signature Authority 516
Summary 517
ftoc.indd xviftoc.indd xvi 12/19/07 3:17:04 PM12/19/07 3:17:04 PM
Contents
xvii
Chapter 23: Drag and Drop, and the Clipboard 519
Drag-and-Drop Events 520
A Simple Example 521
Learning Data Types Available 523
Dragging Within an Application 524
Accepting Dropped Files 525
Dragging Objects 526
Changing Format Names 528
Dragging Multiple Data Formats 529
Using the Clipboard 532
Summary 535
Chapter 24: UAC Security 537
UAC Overview 537
Designing for UAC 538

Elevating Programs 542
User 542
Calling Program 542
Called Program 543
Summary 544
Part III: Object-Oriented Programming 545
Chapter 25: OOP Concepts 547
Classes 547
Encapsulation 549
Inheritance 550
Inheritance Hierarchies 552
Refinement and Abstraction 552
“Has-a” and “Is-a” Relationships 554
Adding and Modifying Class Features 555
Interface Inheritance 557
Polymorphism 558
Overloading 559
Extension Methods 560
Summary 561
ftoc.indd xviiftoc.indd xvii 12/19/07 3:17:04 PM12/19/07 3:17:04 PM
Contents
xviii
Chapter 26: Classes and Structures 563
Classes 563
Attribute_list 564
Partial 564
Accessibility 565
Shadows 566
Inheritance 567
Of type_list 568

Inherits parent_class 569
Implements interface 570
Structures 573
Structures Cannot Inherit 574
Structures Are Value Types 574
Memory Required 575
Heap and Stack Performance 577
Object Assignment 577
Parameter Passing 578
Boxing and Unboxing 580
Class Instantiation Details 580
Structure Instantiation Details 582
Garbage Collection 584
Finalize 585
Dispose 587
Constants, Properties, and Methods 589
Events 591
Declaring Events 591
Raising Events 593
Catching Events 593
Declaring Custom Events 595
Shared Variables 599
Shared Methods 600
Summary 602
Chapter 27: Namespaces 605
The Imports Statement 606
Automatic Imports 607
Namespace Aliases 609
Namespace Elements 610
The Root Namespace 610

Making Namespaces 611
Classes, Structures, and Modules 613
ftoc.indd xviiiftoc.indd xviii 12/19/07 3:17:05 PM12/19/07 3:17:05 PM
Contents
xix
Resolving Namespaces 614
Summary 617
Chapter 28: Collection Classes 619
What Is a Collection? 619
Arrays 620
Array Dimensions 621
Lower Bounds 622
Resizing 623
Speed 623
Other Array Class Features 624
Collections 627
ArrayList 627
StringCollection 629
Strongly Typed Collections 629
Read-Only Strongly Typed Collections 631
NameValueCollection 632
Dictionaries 633
ListDictionary 634
Hashtable 635
HybridDictionary 636
Strongly Typed Dictionaries 636
Other Strongly Typed Derived Classes 638
StringDictionary 639
SortedList 639
CollectionsUtil 639

Stacks and Queues 640
Stack 640
Queue 641
Generics 643
Summary 645
Chapter 29: Generics 647
Advantages of Generics 647
Defining Generics 648
Generic Constructors 650
Multiple Types 650
Constrained Types 652
Using Generics 654
Imports Aliases 655
Derived Classes 655
ftoc.indd xixftoc.indd xix 12/19/07 3:17:05 PM12/19/07 3:17:05 PM
Contents
xx
Predefined Generic Classes 656
Generic Methods 656
Generics and Extension Methods 657
Summary 658
Part IV: Graphics 659
Chapter 30: Drawing Basics 661
Drawing Overview 661
Drawing Namespaces 663
System.Drawing 663
System.Drawing.Drawing2D 665
System.Drawing.Imaging 668
System.Drawing.Text 669
System.Drawing.Printing 672

Graphics 673
Drawing Methods 673
Filling Methods 679
Other Graphics Properties and Methods 679
Anti-Aliasing 682
Transformation Basics 684
Advanced Transformations 688
Saving and Restoring Graphics State 692
Drawing Events 693
Summary 695
Chapter 31: Brushes, Pens, and Paths 697
Pen 697
Alignment 700
CompoundArray 701
Custom Line Caps 702
Pen Transformations 703
Brush 705
SolidBrush 706
TextureBrush 706
HatchBrush 709
LinearGradientBrush 709
PathGradientBrush 714
GraphicsPath Objects 719
Garbage-Collection Issues 723
Summary 726
ftoc.indd xxftoc.indd xx 12/19/07 3:17:05 PM12/19/07 3:17:05 PM
Contents
xxi
Chapter 32: Text 727
Drawing Text 728

Text Formatting 728
FormatFlags 731
Tab Stops 734
Trimming 735
MeasureString 736
Font Metrics 739
Summary 743
Chapter 33: Image Processing 745
Image 745
Bitmap 747
Loading Bitmaps 748
Saving Bitmaps 749
Implementing AutoRedraw 751
Pixel-by-Pixel Operations 753
Metafile Objects 757
Summary 760
Chapter 34: Printing 761
How Not to Print 761
Basic Printing 762
Printing Text 766
Centering Printouts 773
Fitting Pictures to the Page 775
Simplifying Drawing and Printing 777
Summary 780
Chapter 35: Reporting 781
Report Objects 781
Building a Report 782
CrystalReportViewer 794
Customizing a Report 795
External Reports 799

ReportDocument 799
Summary 801
ftoc.indd xxiftoc.indd xxi 12/19/07 3:17:05 PM12/19/07 3:17:05 PM
Contents
xxii
Part V: Interacting with the Environment 803
Chapter 36: Configuration and Resources 805
My 805
Me and My 806
My Sections 807
Environment 807
Setting Environment Variables 808
Using Environ 808
Using System.Environment 809
Registry 811
Native Visual Basic Registry Methods 812
My.Computer.Registry 814
Configuration Files 816
Resource Files 821
Application Resources 821
Using Application Resources 822
Embedded Resources 823
Satellite Resources 824
Localization Resources 826
ComponentResourceManager 827
Application 830
Application Properties 830
Application Methods 831
Application Events 833
Summary 835

Chapter 37: Streams 837
Stream 838
FileStream 839
MemoryStream 840
BufferedStream 841
BinaryReader and BinaryWriter 841
TextReader and TextWriter 843
StringReader and StringWriter 844
StreamReader and StreamWriter 845
OpenText, CreateText, and AppendText 846
Custom Stream Classes 848
Summary 848
ftoc.indd xxiiftoc.indd xxii 12/19/07 3:17:05 PM12/19/07 3:17:05 PM

×