Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 1.816 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
1.816
Dung lượng
9,06 MB
Nội dung
Table of Contents Index Microsoftđ Visual C#đ NET 2003 Developer's Cookbook By Mark Schmidt, Simon Robinson Publisher : Sams Publishing Pub Date : December 19, 2003 ISBN : 0-672-32580-2 Pages : 816 What do you need when you are coding in C#? If your answer is easily understood recipes for code that does something, then this is the book for you! You probably already have a handle on the basics of NET programming and are in need of some shortcuts to make your job easier How about 350 code recipes! The Microsoft Visual C# NET 2003 Developer's Cookbook provides a practical reference for various programming tasks Each chapter consists of a brief description of the topic at hand and then gives you the goods - recipes that explain a brief description of the task, the technique and comments about the technique chosen by C# experts, Mark Schmidt and Simon Robinson • • Table of Contents Index Microsoft® Visual C#® NET 2003 Developer's Cookbook By Mark Schmidt, Simon Robinson Publisher : Sams Publishing Pub Date : December 19, 2003 ISBN : 0-672-32580-2 Pages : 816 Copyright About the Authors Acknowledgments We Want to Hear from You! Introduction Part I, The C# Language Part II, User Interface and Graphics Part III, Data Access Part V, Deployment and Security Part IV, Internet and Networking Part VI, Advanced Topics Part I: The C# Language Chapter 1 Operators, Expressions, and Control Structures Section 1.0 Introduction Section 1.1 Understanding Visual C# NET Program Layout Section 1.3 Creating Multiple Application Entry Points Section 1.2 Parsing Command-Line Arguments Section 1.4 Referencing Assemblies and Namespaces Section 1.5 Creating Valid Identifier Names Section 1.6 Working with Numeric Types Section 1.8 Creating Value Types with struct Section 1.10 Performing Relational Operations Section 1.12 Determining Operator Precedence and Associativity Section 1.14 Using Looping Control Structures Section 1.7 Working with Floating-Point Numbers Section 1.9 Converting Data Types Section 1.11 Using Logical Expressions Section 1.13 Using if Statements Section 1.15 Breaking Out of a Loop Control Body Chapter 2 Objects and Components Section 2.0 Introduction Section 2.1 Creating Classes Section 2.3 Constructing Class Methods Section 2.5 Overloading Operators Section 2.7 Constructing Class Properties Section 2.9 Preventing Object Inheritance Section 2.11 Abstract Classes and Interfaces Section 2.13 Creating and Using Class Libraries Section 2.2 Defining Class Fields Section 2.4 Instantiating and Using Objects Section 2.6 Overloading Class Constructors Section 2.8 Inheriting from Other Classes Section 2.10 String Representation of Objects Section 2.12 Multiple Inheritance Using Interfaces Chapter 3 Strings and Regular Expressions Section 3.0 Introduction Section 3.1 Creating and Using String Objects Section 3.3 Accessing Individual String Characters Section 3.5 Case-Insensitive String Comparison Section 3.7 Using Verbatim String Syntax Section 3.9 Optimizing StringBuilder Performance Section 3.2 Formatting Strings Section 3.4 Analyzing Character Attributes Section 3.6 Working with Substrings Section 3.8 Choosing Between Constant and Mutable Strings Section 3.10 Understanding Basic Regular Expression Syntax Section 3.11 Validating User Input with Regular Expressions Section 3.12 Replacing Substrings Using Regular Expressions Section 3.13 Building a Regular Expression Library Chapter 4 Creating and Using NET Collections Section 4.0 Introduction Section 4.1 Declaring and Using Arrays Section 4.3 Enumerating Arrays with the foreach Operator Section 4.4 Determining the Current Element Index Within a foreach Loop Section 4.5 Using ArrayLists Section 4.2 Defining Jagged Arrays Section 4.6 Choosing Between an Array and an ArrayList Section 4.7 Using Stacks and Queues Section 4.9 Working with BitArrays Section 4.11 Sorting Collections Section 4.13 Creating New Collection Types Section 4.8 Using Hashtables Section 4.10 Enumerating Collections with IEnumerator Section 4.12 Binary Searching with Arrays Section 4.14 Creating Indexers Chapter 5 Delegates and Events Section 5.0 Introduction Section 5.1 Defining and Using Delegates Section 5.3 Removing Individual Delegates from Multicast Delegates Section 5.5 Calling Delegates Asynchronously Section 5.7 Declaring Events Section 5.9 Packaging Event Arguments Chapter 6 Exceptions and Error Handling Section 5.2 Combining Delegates to Form Multicast Delegates Section 5.4 Accessing Delegate Names Within a Multicast Delegate Section 5.6 Return Values for Multicast Delegates Section 5.8 Defining and Registering Event Handlers Section 6.0 Introduction Section 6.1 Using try/catch blocks Section 6.3 Displaying Exception Information Section 6.5 Accessing Inner Exceptions Section 6.2 Using a finally Block Section 6.4 Creating and Throwing Custom Exceptions Section 6.6 Overflow Detection Using Checked and Unchecked Part II: User Interface and Graphics Chapter 7 Windows Forms Section 7.0 Introduction Section 7.1 Creating a Dialog-Based Windows Form Section 7.3 Creating Modal Dialog Boxes Section 7.5 Handling Form Events Section 7.7 Changing a Windows Form Icon Section 7.9 Changing Form Opacity Section 7.11 Creating MDI Forms Section 7.13 Arranging MDI Child Forms Section 7.2 Changing a Form's Properties Section 7.4 Displaying Message Boxes Section 7.6 Designating the Initial Windows Form Section 7.8 Assigning Custom Data to a Windows Form Section 7.10 Supporting Drag and Drop Operations Section 7.12 Accessing MDI Child Windows Chapter 8 Windows Forms Controls Section 8.0 Introduction Section 8.1 Displaying Text with a Label Control Section 8.3 Creating a Button and Handling Events Section 8.5 Creating and Attaching Menus to a Windows Form Section 8.7 Displaying System Tray Icons Section 8.8 Opening Web Pages with a LinkLabel Control Section 8.10 Creating Grouped Radio Buttons Section 8.12 Adding and Removing Items in a ListBox Control Section 8.14 Using ImageLists in a ListView Control Section 8.16 Creating ListView Columns Section 8.18 Programmatically Adding Items to a TreeView Control Section 8.2 Changing Control Properties Section 8.4 Displaying an Open File Dialog Box Section 8.6 Creating Context Menus Section 8.9 Determining Check Box State Section 8.11 Determining the Selected Radio Button Section 8.13 Using a ListView Control Section 8.15 Changing a ListView Mode Section 8.17 Using the TreeNode Editor Section 8.19 Using Images in a TreeView Section 8.20 Selecting Items Using the PathSeparator Property Section 8.21 Creating ToolBars Section 8.22 Capturing ToolBar Button Clicks Section 8.24 Adding Tooltips to Controls Section 8.26 Docking Controls Section 8.28 Visual Inheritance Section 8.23 Adding StatusBar Panels to Display Application State Section 8.25 Anchoring Controls Section 8.27 Implementing Control Validation Chapter 9 User Controls Section 9.0 Introduction Section 9.1 Extending Common Controls Section 9.3 Creating Custom Controls Section 9.5 Changing a Control's Toolbox Icon Section 9.7 Creating Extender Provider Controls Section 9.9 Utilizing Custom Designers Section 9.11 Removing Control Properties Using Metadata Filtering Section 9.2 Creating Composite Controls Section 9.4 Using Design-Time Attributes Section 9.6 Programmatically Adding Controls to the Toolbox Section 9.8 Creating a UI Type Editor Section 9.10 Extending the Design Time Context Menu Chapter 10 Programming Graphics with GDI+ Section 10.1 Obtaining a Graphics Object Section 10.3 Drawing a Rectangle with a Hatch Brush Section 10.5 Using Gradient Fills Section 10.7 Drawing Arc and Pie Shapes Section 10.9 Using Graphics Containers Section 10.11 Performing Flicker-Free Animation Section 10.0 Introduction Section 10.2 Drawing a Rectangle Section 10.4 Filling a Rectangle with a Texture Brush Section 10.6 Drawing Connected Lines and Polygons Section 10.8 Using Rotation and Translation Transformations Section 10.10 Forcing a Repaint Section 10.12 Enumerating System Fonts Section 10.13 Displaying Text Section 10.14 Enabling Antialiasing Section 10.15 Loading and Displaying Images Section 10.16 Loading and Displaying Animated GIF's Section 10.17 Converting Image File Formats Section 10.19 Displaying a Print Preview Dialog Section 10.18 Printing Documents Chapter 11 Localization and Resources Section 11.0 Introduction Section 11.1 Determining a User's Culture Information Section 11.3 Programmatically Changing the Current Culture Section 11.5 Using Fallback Resource for Unsupported Regions Section 11.7 Displaying Culture Aware Date and Time Section 11.9 Creating and Using Satellite Assemblies Section 11.11 Saving Resource Information Using the ResourceWriter Class Section 11.2 Localizing Windows Forms Controls Section 11.4 Enumerating Culture Types Section 11.6 Formatting Numbers Correctly Based on Culture Section 11.8 Formatting Currency for a Specific Culture Section 11.10 Using ResourceReader to Display an Image Resource Part III: Data Access Chapter 12 File I/O and Serialization Section 12.0 Introduction Section 12.1 Creating a New File Section 12.3 Opening a File for Reading Using the File Class Section 12.5 Copying and Moving a File Section 12.7 Writing to a File Section 12.9 Appending Data to an Existing File Section 12.11 Monitoring File and Directory Changes Section 12.2 Verifying the Existence of a File Section 12.4 Using the FileInfo Class to Display File Information Section 12.6 Making a File Read Only Section 12.8 Reading from a File Section 12.10 Improving Performance with a MemoryStream Section 12.12 Creating a Directory Section 12.13 Retrieving Directory Information Section 12.14 Enumerating Files and Subdirectories in a Directory Section 12.15 Saving Object State with Serialization Section 12.16 Recreating Objects with Deserialization Section 12.18 Customizing the Serialization Process Section 12.17 Preventing Object Items from Being Serialized Chapter 13 XML in NET Section 13.0 Introduction Section 13.2 Reading with XmlNodeReader Section 13.4 Using XmlConvert to Convert XML Data Types Section 13.6 Programmatically Generating XML Documents Section 13.8 Working with XML Namespaces Section 13.1 Reading XML Documents with XmlTextReader Section 13.3 Navigating XML Documents with XPath Section 13.5 Validating XML Documents with Schemas Section 13.7 Controlling XmlTextWriter Formatting Section 13.9 Transforming XML Documents with XSLT Chapter 14 Database Programming with ADO.NET Section 14.1 Creating a Database Connection Section 14.3 Generating an XML Schema for an Untyped DataSet Section 14.5 Creating Forms with the Data Form Wizard Section 14.7 Displaying a DataGrid Section 14.9 Using CommandBuilder to Automatically Generate Commands Section 14.10 Creating Different DataViews of a Table Section 14.0 Introduction Section 14.2 Creating and Filling DataSets Section 14.4 Reading Database Records Using SqlDataReader Section 14.6 Using Commands and Stored Procedures Section 14.8 Databinding Windows Form Controls Section 14.11 Adding New Tables to a DataSet Section 14.12 Creating Unique Constraints Section 14.14 Inserting New Rows into a DataTable Section 14.16 Navigating Tables Using DataRelations Section 14.13 Creating ForeignKey Constraints Section 14.15 Modifying Rows in a DataTable Section 14.17 Saving DataSet Information to an XML File Section 14.18 Restoring a DataSet from an XML File Section 14.19 Merging DataSets Section 14.21 Ensuring Data Integrity Using Transactions Section 14.20 Modifying Pooling Behavior for SQL Server Connections Part IV: Internet and Networking Chapter 15 Network Programming with Sockets Section 15.0 Introduction Section 15.1 Creating a Stream-Based Server Section 15.2 Determining Connection Client Information Section 15.3 Resolving an IP Address or Hostname Using DNS Section 15.5 Creating a Connectionless UDP-Based Server Section 15.7 Controlling Socket Lingering Behavior Section 15.9 Requesting Web Documents Through a Proxy Server Section 15.4 Creating a Stream-Based Client Section 15.6 Creating a Connectionless UDP-Based Client Section 15.8 Using the WebRequest Class for HTTP Communication Section 15.10 Creating Asynchronous Web Requests Chapter 16 Building ASP.NET Applications Section 16.0 Introduction Section 16.1 Creating a Simple Web Form Section 16.3 Handling Web Control Events Section 16.5 Redirecting Users to a Different Web Page Section 16.7 Databinding Web Controls Section 16.9 Using the DataGrid Control Section 16.11 Creating an Editable DataGrid Section 16.13 Creating Custom Web Controls Section 16.15 Writing and Reading Cookies Section 16.2 Displaying Server-Side Controls Section 16.4 Forcing a Post Back from a Web Control Event Section 16.6 Validating Input Data and Displaying Errors Section 16.8 Using the DataList Web Control Section 16.10 Changing DataGrid Style Information Section 16.12 Managing Application and Session State Section 16.14 Using Page Output Caching Chapter 17 ASP.NET Web Services Section 17.0 Introduction Section 17.1 Creating an ASP.NET Web Service using statements purpose of [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] validation character attribute determination 2nd 3rd 4th 5th 6th CompareValidator, ASP.NET CustomValidator, ASP.NET ErrorProvider control for 2nd 3rd 4th RangeValidator, ASP.NET regular expressions for 2nd 3rd RegularExpressionValidator, ASP.NET RequiredFieldValidator, ASP.NET ValidationSummary, ASP.NET variables Autos window for viewing fields as Locals window for viewing viewing values during debugging 2nd 3rd verbs creating context menus from 2nd 3rd defined verification skipping, assemblies 2nd versioning assemblies 2nd 3rd format for 2nd ViewState defined operation of virtual directories created for ASP.NET Web Services projects in virtual keyword methods with overriding methods 2nd Visual Studio IDE auto hide feature bookmarks Class View window docking windows Dynamic Help IntelliSense 2nd layouts, preset outlining 2nd profiles Properties window Resource window Server Explorer window Solution Explorer 2nd source code editing 2nd 3rd 4th source regions Task List 2nd toolbars Toolbox window [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] WaitAll method 2nd WaitAny method WaitOne method watch windows 2nd Web browsers opening from Windows Forms links Web controls mobile Web Forms client-side events 2nd 3rd code-behind files controls, server-side [See server-side controls] creating projects custom controls, creating 2nd 3rd 4th databinding 2nd 3rd 4th 5th 6th 7th DataGrid control 2nd 3rd 4th 5th 6th 7th DataList controls 2nd 3rd 4th 5th 6th delegates, event designer, mobile Web pages event handling 2nd 3rd 4th 5th 6th 7th 8th files for JavaScript with 2nd 3rd mobile device pages 2nd 3rd 4th 5th 6th 7th 8th 9th 10th ObjectList control 2nd 3rd 4th order of calls page layout options postbacks redirection 2nd Response objects server-side controls, adding 2nd 3rd static variables validation 2nd 3rd 4th 5th viewing code Web Services, consuming 2nd Web Forms authentication 2nd 3rd 4th Web requests, asynchronous 2nd 3rd 4th 5th Web Service Description Language [See WSDL] Web Services asmx files aliasing Web methods 2nd Application object ASP.NET, consuming from 2nd asynchronous methods 2nd 3rd browsing for client construction 2nd 3rd 4th 5th 6th code-behind files for, viewing consuming 2nd 3rd 4th 5th 6th creating simple 2nd 3rd 4th description documents design view for discovery files error detection headers methods, adding 2nd 3rd methods, descriptions of 2nd Namespace class proxy classes for clients 2nd publishing 2nd purpose of references to, adding to forms registering 2nd session state 2nd 3rd state maintenance 2nd 3rd tModels transaction methods 2nd types allowed for methods UDDI with 2nd virtual directory creation Web Forms, consuming from 2nd WebMethod attribute 2nd 3rd 4th 5th WebService attribute 2nd 3rd Windows Forms, consuming from 2nd 3rd 4th WSDL documents Web setup projects 2nd web.config forms authentication with WebProxy objects 2nd WebRequest class 2nd 3rd WebResponse class well-known objects specification While loops 2nd 3rd whitespace characters, testing for Windows CE [See also mobile devices] Dynamic Link Library projects SqlServerCE 2nd 3rd 4th 5th 6th 7th 8th Windows Form designer composite controls, creating defined InitializeComponent method Property window 2nd Windows Forms ActiveX controls in 2nd base class for child form access 2nd 3rd 4th child form arrangement 2nd child form creation 2nd Closing event code model of 2nd configuration files for 2nd 3rd 4th context menus for 2nd controls [See Windows Forms controls] creating simple applications 2nd 3rd 4th Data Form Wizard 2nd 3rd DataGrid control 2nd DataGrid control with defined designer [See Windows Form designer] Dispose method drag and drop support 2nd 3rd 4th events, handling 2nd 3rd 4th 5th Form base class group containers 2nd icon for, setting 2nd 3rd images, displaying 2nd inheritance of 2nd initial form, setting 2nd InitializeComponent method irregularly shaped forms Load event MDI form access 2nd 3rd 4th MDI form arrangement 2nd MDI form creation 2nd menu creation for 2nd message boxes with 2nd 3rd 4th 5th mobile device applications 2nd 3rd modal dialog boxes, forms as 2nd opacity settings 2nd 3rd project creation properties, configuration files for 2nd 3rd 4th properties, setting 2nd SelectionRules property, Design class Smart Device applications 2nd 3rd system tray icons 2nd Text property timers transparency settings 2nd 3rd viewing code Web Services, consuming 2nd 3rd 4th Windows Forms controls anchoring controls 2nd buttons 2nd 3rd 4th CheckBox control 2nd collapsible controls 2nd 3rd composite, creating 2nd context menus for 2nd customizing 2nd 3rd 4th 5th 6th databinding 2nd 3rd 4th 5th 6th DataGrid control docking controls 2nd 3rd 4th 5th ErrorProvider control for 2nd 3rd 4th event handling 2nd 3rd 4th events associated with group containers for 2nd GroupBox control ImageList control 2nd 3rd inheritance with Label control 2nd 3rd Language property LinkLabel control 2nd ListBox control 2nd 3rd 4th 5th ListView control 2nd 3rd 4th 5th 6th localization of 2nd MainMenu control 2nd NotifyIcon control 2nd open file dialog box 2nd Panel controls properties, changing programatically properties, setting in designer 2nd 3rd RadioButton control 2nd 3rd 4th resizing for localization StatusBar controls 2nd ToolBar controls 2nd 3rd 4th 5th 6th toolbox icons for 2nd toolbox, adding to programmatically 2nd 3rd 4th ToolTip control 2nd TreeView control 2nd 3rd 4th 5th 6th validating input 2nd 3rd 4th Windows Installer msi files .msm files automatic repair feature conditional installs with 2nd 3rd derived classes, recognizing INSTALLTOOLS property 2nd 3rd properties of 2nd WindowsPrincipal objects IsInRole method 2nd 3rd WM_PAINT message worker threads wrappers, COM 2nd 3rd 4th 5th writing to files TextWriter class for Write method for 2nd 3rd 4th 5th XmlTextWriter class for 2nd 3rd WSDL (Web Service Description Language) elements of files example file message elements namespace declarations purpose of reflection to generate files tModels UDDI with Web method elements 2nd 3rd 4th [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] XML attribute creation 2nd attribute punctuation converting data types 2nd 3rd CreateAttribute method 2nd creating document 2nd 3rd 4th DataSets, restoring from XML 2nd 3rd DataSets, saving to XML 2nd 3rd 4th 5th defined document generation 2nd 3rd 4th element creation entity declarations formatting 2nd 3rd indentation control insertion methods namespaces 2nd 3rd 4th 5th node selection exceptions opening XML files 2nd 3rd 4th 5th 6th 7th 8th parsing with XmlNodeReader 2nd 3rd 4th 5th parsing with XmlTextReader 2nd 3rd 4th 5th 6th 7th 8th performance issues Read method resolving entity references Save method 2nd 3rd SAX schemas 2nd 3rd SelectSingleNode method 2nd 3rd 4th string comparisons stylesheets 2nd 3rd 4th TreeView controls, populating 2nd 3rd 4th 5th 6th type specification validating with schemas 2nd 3rd XmlConvert class 2nd 3rd XmlDocument class 2nd 3rd 4th 5th XmlNameTable class XmlNodeReader 2nd 3rd 4th 5th XmlNodeType xmlns XmlResolver class XmlTextReader class 2nd 3rd 4th 5th 6th 7th 8th XmlTextWriter class 2nd 3rd XmlValidatingReader class 2nd 3rd XPath 2nd 3rd 4th XPathNavigator method XSLT 2nd 3rd 4th XML serialization 2nd 3rd 4th XPath attribute selection with defined expressions, generating namespaces with 2nd node selection with 2nd relative positioning XPathNavigator method XSLT with XSLT (Extensible Stylesheet Transformations) 2nd 3rd 4th ... Section 6.0 Introduction Section 6.1 Using try/catch blocks Section 6.3 Displaying Exception Information Section 6.5 Accessing Inner Exceptions Section 6.2 Using a finally Block Section 6.4... Section 8.25 Anchoring Controls Section 8.27 Implementing Control Validation Chapter 9 User Controls Section 9.0 Introduction Section 9.1 Extending Common Controls Section 9.3 Creating Custom Controls... Localizing Windows Forms Controls Section 11.4 Enumerating Culture Types Section 11.6 Formatting Numbers Correctly Based on Culture Section 11.8 Formatting Currency for a Specific Culture Section 11.10 Using ResourceReader to Display an Image Resource