1. Trang chủ
  2. » Khoa Học Tự Nhiên

Programming dot NET windows applic

973 52 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

Nội dung

This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com [ Team LiB ] • • • • • • • Table of Contents Index Reviews Examples Reader Reviews Errata Academic Programming NET Windows Applications By Dan Hurwitz, Jesse Liberty Publisher: O'Reilly Pub Date: October 2003 ISBN: 0-596-00321-8 Pages: 1246 With this tutorial, you will explore all aspects of using NET Windows Forms class libraries and the associated programming tools in Visual Studio NET, enabling you to build applications for the Windows 9x, Windows 2000 and Windows XP desktop platforms Step-by-step, you'll learn ways to design applications that either function alone on a PC, or work in combination with your web-based application server to take advantage of the richer interface and higher level of security [ Team LiB ] This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com [ Team LiB ] • • • • • • • Table of Contents Index Reviews Examples Reader Reviews Errata Academic Programming NET Windows Applications By Dan Hurwitz, Jesse Liberty Publisher: O'Reilly Pub Date: October 2003 ISBN: 0-596-00321-8 Pages: 1246 Copyright Preface About This Book How the Book Is Organized Who This Book Is for Conventions Used in This Book Version Support Support: A Note From Jesse Liberty We'd Like to Hear from You Acknowledgments Chapter Windows Forms and the NET Framework Section 1.1 The NET Framework Section 1.2 Windows Forms Chapter Getting Started Section 2.1 System Requirements Section 2.2 Hello World Chapter Visual Studio NET Section 3.1 Overview Section 3.2 Start Page Section 3.3 Projects and Solutions Section 3.4 The Integrated Development Environment (IDE) Section 3.5 Building and Running This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Chapter Events Section 4.1 Publish and Subscribe Section 4.2 Performance Section 4.3 Some Examples Chapter Windows Forms Section 5.1 Web Applications Versus Windows Applications Section 5.2 The Forms Namespace Section 5.3 Form Properties Section 5.4 Forms Inheritance Section 5.5 User Interface Design Chapter Dialog Boxes Section 6.1 Modal Versus Modeless Section 6.2 Form Properties Section 6.3 DialogResult Section 6.4 Termination Buttons Section 6.5 Apply Button Section 6.6 CommonDialog Classes Chapter Controls: The Base Class Section 7.1 Control Class Chapter Mouse Interaction Section 8.1 SystemInformation Properties Section 8.2 Mouse Events Chapter Text and Fonts Section 9.1 Text Section 9.2 Fonts Chapter 10 Drawing and GDI+ Section 10.1 The Drawing Namespace Section 10.2 The Analog Clock Project Chapter 11 Labels and Buttons Section 11.1 Label Section 11.2 Button Classes Chapter 12 Text Controls Section 12.1 Text Section 12.2 Editable Text Controls: TextBoxBase Section 12.3 RichTextBox Chapter 13 Other Basic Controls Section 13.1 Containers Section 13.2 Tabbed Pages Section 13.3 PictureBox Section 13.4 ScrollBar Section 13.5 TrackBar Section 13.6 Up-Down Controls Section 13.7 ProgressBar Chapter 14 TreeView and ListView Section 14.1 Class Hierarchy Section 14.2 Splitter Section 14.3 TreeView Section 14.4 ListView Chapter 15 List Controls Section 15.1 Class Hierarchy Section 15.2 ListControls Chapter 16 Date and Time Controls This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Chapter 16 Date and Time Controls Section 16.1 Class Hierarchy Section 16.2 Date and Time Values Section 16.3 DateTimePicker Section 16.4 MonthCalendar Section 16.5 Timer Component Chapter 17 Custom Controls Section 17.1 Specializing an Existing Control Section 17.2 Creating a User Control Section 17.3 Creating Custom Controls from Scratch Chapter 18 Menus and Bars Section 18.1 Creating Your First Menu Section 18.2 The MainMenu Object Section 18.3 Toolbars Section 18.4 Writing It by Hand Section 18.5 Status Bars Chapter 19 ADO.NET Section 19.1 Bug Database: A Windows Application Section 19.2 The ADO.NET Object Model Section 19.3 Getting Started with ADO.NET Section 19.4 Managed Providers Section 19.5 Binding Data Section 19.6 Data Reader Section 19.7 Creating a DataGrid Chapter 20 Updating ADO.NET Section 20.1 Updating with SQL Section 20.2 Updating Data with Transactions Section 20.3 Updating Data Using DataSets Section 20.4 Multiuser Updates Section 20.5 Command Builder Chapter 21 Exceptions and Debugging Section 21.1 Bugs Versus Exceptions Section 21.2 Exceptions Section 21.3 Throwing and Catching Exceptions Section 21.4 Bugs Section 21.5 Debugging in Visual Studio NET Section 21.6 Assert Yourself Chapter 22 Configuration and Deployment Section 22.1 Class Hierarchy Section 22.2 Configuration Section 22.3 Assemblies Section 22.4 Build Configurations Section 22.5 Deployment Appendix A Characters and Keys Colophon Index [ Team LiB ] This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com [ Team LiB ] Copyright Copyright © 2004 O'Reilly & Associates, Inc Printed in the United States of America Published by O'Reilly & Associates, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472 O'Reilly & Associates books may be purchased for educational, business, or sales promotional use Online editions are also available for most titles (http://safari.oreilly.com) For more information, contact our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly & Associates, Inc Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in this book, and O'Reilly & Associates, Inc was aware of a trademark claim, the designations have been printed in caps or initial caps The association between the image of a darter and the topic of NET Windows applications is a trademark of O'Reilly & Associates, Inc While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein [ Team LiB ] This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com [ Team LiB ] Preface Windows Forms represents the third generation of Windows development When Microsoft first released Windows in 1985, programmers built applications using the Windows API, typically in C Many of us learned how to build these applications from Charles Petzold, and this is a good place to thank him for his seminal book on Windows programming By 1992, many programmers were building Windows applications in C++ using the Microsoft Foundation Classes (MFC) Mike Blaszcack wrote a killer book on this topic, and it remains a classic In essence, the MFC represented an objectoriented wrapper on the more procedural API In the 1990s, the alternative to building C++/MFC applications was using VB and its Rapid Application Development environment Microsoft first announced the third generation of Windows development, Windows Forms, and the NET platform in July 2000 In short, C# (and Visual Basic NET) and Windows Forms replace C++ and the MFC as well as classic VB This book aims to provide a complete tutorial to this new way of creating Windows applications On a personal note, having spent nine years building MFC applications in C++ (and having earned much of my livelihood writing books about C++) you might expect me to have a certain resistance to the new paradigm About an hour after writing my first C#/Windows Forms application, I said to my dog, "I'll never go back, and you can't make me." The improvements were so significant, and the increase in productivity so unmistakable, that there was no doubt in my mind that Windows Forms would totally replace C++/MFC in my development of Windows applications [ Team LiB ] This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com [ Team LiB ] About This Book This book will teach you all you need to know to use Windows Forms effectively We assume you have some background with either C# or Visual Basic NET (VB.NET), or sufficient programming experience to pick up what you need to know from the examples shown Windows Forms is not difficult All of its concepts are straightforward, and the Visual Studio NET environment makes building powerful applications much simpler than writing code by hand The only difficulty of Windows Forms is that many pieces must be woven together to build a robust, scalable, and efficient application You will find two authors' names on this book Each chapter was written initially by one or the other author, but all chapters were then edited by both authors Jesse Liberty then extensively edited and rewrote every chapter to give the book a more unified voice The chapters were subsequently edited by the O'Reilly editors and then again by the authors The bottom line is that although two authors wrote this book, it should read as if it were written by a single author [ Team LiB ] This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com [ Team LiB ] How the Book Is Organized Chapter is an introduction to Windows Forms and the NET Framework, and is compatible with NET 1.1 and Visual Studio 2003 Chapter covers system requirements and walks you through the creation of several simple "Hello World" applications, using both a text editor and Visual Studio NET Chapter gives a thorough review of the Integrated Development Environment (IDE) that is provided by Microsoft for developing NET applications Chapter covers the use of events in NET Forms applications, and includes extensive examples involving keyboard events and text box validation Chapter covers topics common to all NET Forms applications, including the Form class and the Control class, as well as a discussion of forms inheritance and user interface design Chapter describes the different types of dialog boxes, including those you can create from scratch and those provided as part of the CommonDialog classes Chapter covers the features common to all controls in NET Forms, including such things as parent/child relationships, ambient properties, size and location, anchoring and docking, and keyboard interaction It also describes image lists Chapter covers the use of the mouse with NET Windows applications, including mouse events and properties Chapter discusses the use of the written word as part of Windows applications, including the Font class and techniques for drawing and measuring text strings Chapter 10 covers the Drawing namespace, which provides support for rendering graphics as part of a NET application It also includes a sample project, which creates a wicked cool analog clock on your screen Chapter 11 begins the detailed coverage of the native controls available to the NET developer This chapter covers labels, link labels, buttons, checkboxes, and radio buttons Chapter 12 continues the discussion of native controls, with descriptions of the editable text controls, including the text box and rich text box Chapter 13 covers the rest of the native basic controls, including containers such as the panel and the group box, tabbed pages, the picture box, scrollbars and trackbars, up-down controls (sometimes known as spinners), and the progress bar Chapter 14 describes the controls necessary to create hierarchical user interfaces as typified by Windows Explorer A clone of Windows Explorer is developed as an exercise Chapter 15 describes native controls used for presenting lists, including the listbox, the checked listbox, and the combo box Chapter 16 starts with the techniques that deal with date and time values in NET, including the DateTime and TimeSpan structures It then describes the DateTimePicker and MonthCalendar controls and the Timer component Chapter 17 describes how you can create your own controls to use when the native controls don't what your application needs These custom controls can extend or combine existing controls or can be built entirely from scratch Chapter 18 describes the provisions for creating menus, toolbars, and status bars in NET Forms applications Chapter 19 covers the NET database technology and how to use databases in your applications Chapter 20 describes how to update the data in your database, including the use of transactions and multiuser updates Chapter 21 describes error handling and debugging in the NET Framework, including the debugger included as part of Visual Studio NET Chapter 22 describes how to configure and deploy NET Windows applications It also includes a description of NET assemblies The Appendix A lists several tables of data useful to NET programmers, including the ASCII character set, members of the KeyCode enumeration for mapping keyboard keys, and standard and system color names [ Team LiB ] This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com [ Team LiB ] Who This Book Is for This book was written for programmers and web developers who want to build desktop applications using Microsoft's powerful new NET platform Many readers will have experience with the Microsoft Foundation Classes or writing to the Windows API, but they may find that while the Windows Forms applications accomplish the same tasks, the approach is often quite different It might be helpful to first read a primer on C# or VB.NET (see Jesse Liberty's Programming C# (O'Reilly) or Programming Visual Basic NET (O'Reilly)), but this is not required Experienced VB, Java, or C++ developers may decide that they can pick up what they need to know about the languages just by working through the exercises in this book [ Team LiB ] This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com [ Team LiB ] Conventions Used in This Book The following font conventions are used in this book: Italic is used for: Pathnames, filenames, and program names Internet addresses, such as domain names and URLs New terms where they are defined Constant Width is used for: Command lines and options that should be typed verbatim Constant-Width Italic is used for replaceable items, such as variables or optional elements, within syntax lines or code Constant-Width Bold is used for emphasis within program code Indicates C# code Indicates VB.NET code Pay special attention to notes set apart from the text with the following icons: This is a tip It contains useful supplementary information about the topic at hand This is a warning It helps you solve and avoid annoying problems [ Team LiB ] This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com updating, based on menu info StatusBar object adding to form properties stepping through code (debugging) stored procedures, SQL Command objects and spAddBug spAddBugWithTransactions spBugsWithIDs spDeleteBugFromDataSet spUpdateBugFromDataSet updating bugs StreamReader object, printing files String Collection Editor StringDraw class, Analog Clock project strings DateTime structure format list controls, adding to strong names, shared assemblies creating delayed signing subscribing, events syntax errors debugging Visual Studio NET system requirements CLR and software installation system-defined colors system.diagnostics section (configuration files) System.Drawing namespace Color structure geometric structures ordered pairs of numbers locations Point/PointF structures coordinates Rectangle/RectangleF structures constructors properties rectangular areas size Size/SizeF structures width/height system.net section (configuration files) system.runtime.remoting section (configuration files) system.web section (configuration files) System.Windows.Forms namespace 2nd [See also Form class, Forms namespace] system.windows.forms section (configuration files) System.Windows.Forms.CommonDialog class [See CommonDialog class] System.Windows.Forms.Control class 2nd [See also Control class] System.Windows.Forms.Form class SystemColors class, properties SystemInformation class properties Graphics objects and mouse SystemInformation.DoubleClickTime, mouse clicks and This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com [ Team LiB ] This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com [ Team LiB ] [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] tab order of controls TabAlignment enumeration TabAppearance enumeration tabbed pages VB.NET TabControl C# properties Alignment Appearance Padding TabPages SelectedIndexChanged event tab pages, adding VB.NET tables bug database (ADO.NET) BugHistory Bugs table DataSet, adding Tables property, DataSet class TabPage class methods properties TabPage objects TabPageCollection class methods properties TabPages C# VB.NET TabSizeMode enumeration /target parameter, values Teeter Totter control C# code controls event handlers events, publishing properties testing VB.NET templates, Visual Studio NET projects termination buttons, dialog boxes testing, application deployment and text [See also fonts] alignment appearance ASCII bytes of data characters, placing components content definition fonts This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com format formatting leading spacing strikethrough strings, DrawString method Unicode characters text editors, Hello World program Text property buttons ComboBox controls Label control mouse buttons, event handlers TextBox LostFocus event validate contents TextBox control MenuItem objects methods C# VB.NET Notepad and properties AcceptTab C# VB.NET WordPad and TextBoxBase class events hierarchy methods 2nd Modified property C# VB.NET properties TextChanged event, VB.NET TextChanged event TextBoxBase class C# VB.NET TextWriterListener third-party editors This window (debugging code) Threads window (debugging code) ThreeDCheckBoxes property, CheckedListBox controls ThreeState property, CheckBox control throw statement Tick event Timer component 2nd Interval property ticks, time time 2nd [See also date] strings ticks Timer component forms, adding to methods properties Tick event 2nd Interval propety This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com VB.NET timers Analog Clock project countdown timer status bar setting types Times New Roman font, serifs TimeSpan structure constructors methods operators properties Toggle Indeterminate button, CheckedListBox controls Toolbar control adding to form properties ToolBarButtonCollection Editor toolbars appearance button clicks comboboxes creating by hand Debug docked event handlers ImageList 2nd properties tool tips ToolTips ToolBarsByHand.cs ToolBarsByHand.vb Toolbox Tools menu, Visual Studio NET ToolTips 2nd TopIndex property, ListBox control Trace class methods Trace statements compared to Debug tracing assembly build configuration TrackBar control C# events properties transactions ACID test Connection Transaction consistency DataBase database transactions database updates and DB Transaction C# code implementation VB.NET definition durability implementing instantiation This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com isolation 2nd spAddBug stored procedure spAddBugWithTransactions support, adding updating databases, filling ListBoxes transforms coordinates, Analog Clock project page transforms RotateTransform method world transforms Analog Clock project TranslateTransform method tree view nodes TreeNode control methods properties TreeNode objects, tree view and TreeNodeCollection control methods properties TreeView control C# constructor docking events Explorer style interfaces methods CollapseAll ExpandAll populating tree properties SelectedNode recursion ShowPlusMinus property VB.NET TrueType fonts 2nd [See also OpenType fonts] try statements try/catch blocks txt file extension type attribute, configuration files typography text/leading notation [ Team LiB ] This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com [ Team LiB ] [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] UI (user interface) color and consistence and console applications controls and conventions and design design, principles of error handling Explorer style keyboard equivalents MDI modal dialogs readability and SDI (Single Document Interface) tabbed text and text boxes and Undo menu item event handler Unicode characters unwinding the stack (exception handling) up-down controls Update method, DataAdapter UpdateCommand, SqlCommand object UpdateDatabase button UpdateDBTransaction method updating databases concurrency and DataSets and C# VB.NET multiuser updates SQL and hand-edited C# code hand-edited VB.NET code transactions and ListBoxes, filling updating DataSets application concurrency and C# VB.NET records UpDownBase class DomainUpDown control NumericUpDown control properties URLs, Internet application deployment user controls, Windows Forms user input, dialog boxes User Interface editor, application deployment user interface, web applications UserControl This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com creating Teeter Totter control [ Team LiB ] This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com [ Team LiB ] [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] Validating event, TextBox validation, TextBox contents ValueMember property, ListControls variables examining, debugging code member variable, Analog Clock project yButtonSize vbproj files versioning application code vertical line spacing View menu, Visual Studio NET View properties, ListView control visual inheritance Visual Studio NET advantages 2nd application deployment, Setup Wizard building applications code completion Configuration Manager context-sensitive help controls, location customization database wizards DataGrid Debug mode compared to Release mode Debug toolbar debugging DialogapplyEvent project Downloads editing and Get Started Headlines Hello World program as console application as Windows application as Windows application with button HTML editor IDE layout inheritance InitializeComponent method IntelliSense 2nd commands menus Edit menu File menu Project menu Tools menu View menu menus, creating Online Community projects names running applications Search Online This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Solution Explorer solutions sln files solution items splitters Start Page syntax errors system requirements toolbars Web Hosting What's New windows command window Document Outline floating Macro Explorer Object Browser window Task List XML Web Services z-order [ Team LiB ] This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com [ Team LiB ] [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] Watch window (debugging code) web applications web services Windows applications comparison Web Forms Web Hosting, Visual Studio NET Start Page web services well-formed XML What's New, Visual Studio NET Start Page WindForm_Bugs database Window menu, Visual Studio NET Windows applications Hello World program, Visual Studio NET 2nd web applications comparison Windows Control Library Windows Explorer clone, ListView control activation C# events form creation label editing menus populating sorting subitems VB.NET Windows Forms VB.NET and Visual Studio NET Windows Forms user controls Windows Installer, application deployment windows, Visual Studio NET pushpin icon wizards, Visual Studio NET databases WordPad RichTextBox control and TextBox control and world coordinates transformations world transforms Analog Clock project world translations, matrices and WYSIWYG (What You See Is What You Get), Visual Studio NET and [ Team LiB ] This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com [ Team LiB ] [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] x coordinate Analog Clock project float variables computing XCOPY application installation XCopy deployment XML configuration files well-formed XML Web Services, Visual Studio NET Start Page [ Team LiB ] This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com [ Team LiB ] [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] y coordinate, computing yPosition variable, Location property [ Team LiB ] This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com [ Team LiB ] [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] z-order, Splitter control [ Team LiB ] This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Brought to You by Like the book? Buy it! ... the NET Framework, including the debugger included as part of Visual Studio NET Chapter 22 describes how to configure and deploy NET Windows applications It also includes a description of NET. .. and discussion on Windows Forms and the NET Framework, see the O'Reilly & Associates web site: http://www.oreilly.com and the O'Reilly NET DevCenter: http://www.oreillynet.com/dotnet [ Team LiB... LiB ] Chapter Windows Forms and the NET Framework NET is a new development framework that provides a fresh application programming interface to the services and APIs of classic Windows operating

Ngày đăng: 25/03/2019, 15:06

TỪ KHÓA LIÊN QUAN