Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 786 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
786
Dung lượng
12,16 MB
Nội dung
[ Team LiB ] [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] [Y] [Z] obj prefix 2nd Object Browser 2nd 3rd object data type Object Example application Clear() method 2nd 3rd CreateGraphics() method creating 2nd Dispose() method 2nd DrawLine() method 2nd 3rd object instantiation 2nd testing 2nd object models object-oriented programming 2nd object-oriented programming [See OOP] objects 2nd 3rd 4th [See also classes, interfaces] forms [See also controls] Application instantiating 2nd binding 2nd early binding 2nd 3rd late binding 2nd collections Collections Example application 2nd 3rd defined looping through 2nd 3rd structure of COM (Component Object Model) containers defined DataAdapter 2nd DataRow 2nd DataTable adding records to 2nd 3rd 4th creating 2nd deleting records from 2nd editing records in navigating 2nd 3rd 4th 5th defined Directory 2nd encapsulation 2nd 3rd events accessing 2nd 3rd support for triggering 2nd File [See File object] Font 2nd forms sizing forms [See forms] Graphics 2nd creating 2nd 3rd 4th 5th disposing of 2nd methods 2nd 3rd 4th 5th 6th 7th 8th 9th 10th instantiating 2nd 3rd 4th 5th 6th lifecycle of 2nd methods availability of methods 2nd calling 2nd defined naming 2nd Object Browser 2nd 3rd Object Example application Clear() method 2nd 3rd CreateGraphics() method creating 2nd Dispose() method 2nd DrawLine() method 2nd 3rd object instantiation 2nd testing 2nd object models OleDbConnection 2nd 3rd 4th 5th 6th OleDbDataAdapter 2nd 3rd properties 2nd changing 2nd 3rd 4th 5th changing (Properties window) 2nd 3rd 4th modifying Properties Example application 2nd 3rd 4th Properties window property descriptions read-only 2nd 3rd reading 2nd 3rd 4th setting 2nd 3rd 4th setting (Properties window) viewing (Properties window) Rectangle releasing 2nd 3rd 4th SqlDataAdapter Startup objects 2nd 3rd StringBuilder OK value (DialogResult) OK value (MessageBoxButtons) OKCancel value (MessageBoxButtons) OleDbConnection object 2nd 3rd 4th 5th OleDbDataAdapter object 2nd 3rd OOP (object-oriented programming) [See also classes, objects] encapsulation 2nd 3rd methods instance methods 2nd static methods Opacity property (forms) Open Database command (File menu) Open File dialog box creating Open File dialog boxes creating 2nd 3rd Open File Dialog control 2nd 3rd 4th 5th Open() method OpenFileDialog control Picture Viewer 2nd opening files Open File Dialog control 2nd 3rd 4th projects 2nd operating systems events triggering operators addition (+) Boolean 2nd 3rd And (&&) 2nd Not (!) 2nd Or (||) 2nd Xor (^) 2nd comparison 2nd 3rd concatenation (+) conditional division (/) logical logical negation (!) modulus (%) 2nd multiplication (*) order of precedence 2nd 3rd 4th subtraction (-) Options application check boxes 2nd 3rd group boxes 2nd panels 2nd radio buttons 2nd 3rd Options dialog box Or operator (||) 2nd Order menu commands Bring to Front Send to Back output (project) adding to setup programs 2nd 3rd Output window debugging tool 2nd 3rd [ Team LiB ] Brought to You by Like the book? Buy it! [ Team LiB ] [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] [Y] [Z] ! (logical negation) operator ! (Not) operator 2nd % (modulus) operator 2nd & (ampersand) && (And) operator 2nd () (parenthesis) 2nd () parenthesis (backslash) * (multiplication) operator + (addition) operator + (concatenation) operator - (subtraction) operator .NET Framework technological components / (division) operator /* comment notation // comment notation 2nd // notation code comments /// comment notation = (equal sign) ? (question mark) @ (at symbol) ^ (Xor) operator 2nd _ (underscore) {} (braces) 2nd 3rd | (pipe symbol) || (Or) operator 2nd [ Team LiB ] [ Team LiB ] [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] [Y] [Z] Abort value (DialogResult) AbortRetryIgnore value (MessageBoxButtons) accelerator keys Accept buttons 2nd accessing object events 2nd 3rd accessors [See also methods] get 2nd set 2nd 3rd actions break points 2nd active controls ActiveCaption property (SystemColors class) ActiveCaptionText property (SystemColors class) Add Existing Project dialog box Add menu commands Existing Project Add method 2nd 3rd Add Project Output Group dialog box 2nd Add Reference command (Project menu) Add Reference dialog box 2nd Add Task List Shortcut command (Bookmarks menu) Add Windows Forms command (Project menu) Add() method 2nd Add/Remove Programs dialog box AddDays method AddHours method adding controls to forms 2nd project files 2nd 3rd Adding Controls application 2nd adding [See inserting] addition (+) operator AddMilliseconds method AddMinutes method AddMonths method AddSeconds method AddYears method ADO.NET [See also databases] Data Form Wizard 2nd 3rd 4th 5th 6th DataRow object 2nd DataTable object adding records to 2nd 3rd 4th creating 2nd deleting records from 2nd editing records in navigating 2nd 3rd 4th 5th OleDbConnection object 2nd 3rd 4th 5th OleDbDataAdapter object 2nd 3rd records creating 2nd 3rd 4th 5th deleting 2nd displaying editing navigating 2nd 3rd 4th 5th SqlConnection object SqlDataAdapter object Album Maintenance dialog box CD/Album Catalog application writing code 2nd 3rd 4th Align Control application 2nd text box 2nd 3rd Align Left command (Align menu) Align menu commands Align Left To Grid aligning controls forms 2nd text test boxes 2nd Alphabetic button (Properties window) alphabetical displays Properties window ampersand (&) And operator (&&) 2nd Anchor property (controls) 2nd anchoring controls 2nd 3rd 4th Anchoring Example application And operator (&&) 2nd Application folder location Application objects instantiating 2nd applications Adding Controls 2nd Align Controls 2nd text box 2nd 3rd Anchoring example Automate Excel automation servers 2nd code listing 2nd creating worksheets 2nd manipulating worksheet data 2nd 3rd starting Excel 2nd testing type library references 2nd automation automation servers 2nd type library references 2nd AutoScroll Example 2nd 3rd Button Example 2nd Accept button 2nd button images 2nd Cancel button 2nd Class Programming Example binding 2nd 3rd 4th 5th 6th 7th constructor methods 2nd object instantiation 2nd 3rd object interface 2nd 3rd 4th 5th object properties 2nd 3rd 4th 5th 6th 7th 8th 9th releasing objects 2nd 3rd Collections Example 2nd 3rd Custom Dialog Example 2nd 3rd 4th 5th custom setup programs 2nd build options building 2nd CLR (Common Language Runtime) installation creating 2nd Debug builds files 2nd folders 2nd installation locations multiple applications naming project output 2nd 3rd Release builds running 2nd 3rd Start menu shortcuts 2nd Data Form Example 2nd 3rd 4th 5th 6th Database Example connecting to database 2nd 3rd 4th 5th creating records 2nd 3rd 4th 5th DataAdapters 2nd 3rd DataRows 2nd DataTables 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th deleting records 2nd disconnecting from database 2nd displaying records editing records navigating records 2nd 3rd 4th 5th running 2nd Decisions Example buttons if statement 2nd if statement, nesting if statement;else keyword 2nd 3rd Parse() method text boxes Events Example event handler creation 2nd 3rd user interface creation 2nd Excel automating 2nd 3rd 4th 5th 6th 7th 8th 9th exiting ForExample code listing Label control Keyboard Example 2nd 3rd Lists Example 2nd add list items 2nd 3rd clearing list 2nd 3rd combo boxes 2nd 3rd 4th removing list items 2nd retrieving item information 2nd sorting list 2nd Main() method Manipulating Files checking file existence 2nd copying files 2nd 3rd deleting files displaying file properties 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th moving files 2nd 3rd opening files 2nd 3rd 4th properties renaming files 2nd saving files 2nd 3rd 4th 5th MDI Example 2nd 3rd 4th 5th Method Example 2nd ClearEllipse() method ComputeLength() method DrawEllipse() method 2nd form buttons 2nd method calls 2nd 3rd 4th 5th 6th 7th 8th method parameters 2nd 3rd text box 2nd Mouse Paint 2nd 3rd 4th 5th Object Example Clear() method 2nd 3rd CreateGraphics() method creating 2nd Dispose() method 2nd DrawLine() method 2nd 3rd object instantiation 2nd testing 2nd Options check boxes 2nd 3rd group boxes 2nd panels 2nd radio buttons 2nd 3rd Persisting Graphics bitmap initialization bitmap variables 2nd buttons drawing text 2nd event handlers 2nd freeing resources random number generation text box Picture Viewer browsing for files 2nd 3rd 4th exiting form controls 2nd form name 2nd form size 2nd 3rd form text properties icons 2nd invisible controls 2nd Main() method object names 2nd running 2nd visible controls 2nd 3rd Picture Viewer project creating 2nd 3rd 4th program entry points Properties Example 2nd 3rd 4th buttons 2nd form width and height 2nd 3rd running 2nd running 2nd Switch Example 2nd 3rd 4th Tab Order 2nd 3rd Traditional Controls uninstalling Web development 2nd ASP.NET 2nd Web Forms 2nd 3rd 4th 5th 6th 7th 8th 9th 10th XML Web services 2nd 3rd AppStarting value (Cursor property) Archive attribute (files) arguments defined arithmetic 2nd 3rd 4th addition operations division operations modulus arithmetic 2nd multiplication operations negation operations operator precedence 2nd 3rd 4th subtraction operations arrays data types 2nd bool byte casting 2nd char decimal double float int long object prefixes 2nd sbyte selection guidelines 2nd short string uint ulong 2nd declaring Namespaces and Classes in NET As I mentioned earlier in this book, the NET Framework is composed of classesmany classes Namespaces are the method used to create a hierarchical structure for all these classes, and they help prevent naming collisions A naming collision occurs when two classes have the same name Because namespaces provide a hierarchy, it's possible to have two classes with the same name as long as they exist in different namespaces Namespaces, in effect, create a scope for classes The base namespace in the NET Framework is the System namespace The System namespace contains classes for garbage collection (discussed shortly), exception handling, data typing, and so much more The System namespace is just the tip of the iceberg There are literally dozens of namespaces Table A.1 lists some of the more common namespaces, many of which you've used in this book All the controls that you've placed on forms and even the forms themselves, for example, belong to the System.Windows.Forms namespace Use Table A.1 as a guide; if a certain namespace interests you, I suggest that you research it further in the Visual Studio NET online help Table A.1 Commonly Used Namespaces Namespace Description Microsoft.CSharp Contains classes that support compilation and code generation using the Visual C# NET language Microsoft.VisualBasic Contains classes that support compilation and code generation using the Visual Basic language System Contains fundamental classes and base classes that define commonly used value and reference data types, event handlers, interfaces, attributes, and exceptions This is the base namespace of NET System.Data Contains classes that constitute the ADO.NET architecture System.Diagnostics Contains classes that enable you to debug your application and to trace the execution of your code System.Drawing Contains classes that provide access to the Graphical Device Interface (GDI) basic graphics functionality System.IO Contains classes that allow reading from and writing to data streams and files System.Net Contains classes that provide a simple programming interface to many of the protocols found on the network System.Security Contains classes that provide the underlying structure of the common language runtime security system System.Web Contains classes that provide interfaces that enable browser/server communication System.Windows.Forms Contains classes for creating Windows-based applications that take advantage of the rich user-interface features available in the Microsoft Windows operating system System.Xml Contains classes that provide standards-based support for processing XML All Microsoft-provided namespaces begin with either System or Microsoft Other vendors can provide their own namespaces, and it's possible for you to create your own custom namespaces as well, but that's beyond the scope of this book Hour 17 Interacting with Users Forms and controls are the primary means by which users interact with an application, and vice versa However, program interaction can and often does go deeper than that For example, a program can display customized messages to a user, and it can be finely tuned to deal with certain keystrokes or mouse clicks In this hour, you'll learn how to create functional and cohesive interaction between your application and the user In addition, you'll learn how to program the keyboard and the mouse so that you can expand the interactivity of your program beyond what is natively supported by a form and its controls The highlights of this hour include the following: Displaying messages using the MessageBox.Show() method Creating custom dialog boxes Interacting with the keyboard Using the common mouse events Hour 14 Looping for Efficiency As you develop your Visual C# NET programs, you'll encounter situations in which you'll need to execute the same code statement or statements repeatedly Often, you'll need to execute these statements a specific number of times, but you may need to execute them as long as a certain condition persists (an expression is true) or until a condition occurs (an expression becomes true) Visual C# NET includes constructs that enable you to easily define and execute these repetitive code routines: loops This hour shows you how to use the two major looping constructs to make your code smaller, faster, and more efficient The highlights of this hour include the following: Looping a specific number of times using for statements Looping based on a condition using do while and while statements Q&A Q1: Are there any specific cases in which one loop is appropriate over another? A1: Usually, when you have to walk an index or sequential set of elements (such as referencing all elements in an array), the for loop is the best choice Q2: Should I be concerned about the performance differences between the two types of loops? With today's fast processors, chances are good that the performance difference between the two loop types in any given situation will be overshadowed by the A2: readability and functionality of the best choice of loop If you have a situation in which performance is critical, write the loop using all the ways you can think of, benchmark the results, and choose the fastest loop Managing Projects Before you can effectively create an interface and write code, you need to understand what makes up a Visual C# NET project and how to add and remove various components from within your own projects In this section, you'll learn about the Solution Explorer window and how it's used to manage project files You'll also learn specifics about projects and project files, as well as how to change a project's properties Hour 18 Working with Graphics Visual C# NET provides an amazingly powerful array of drawing capabilities, but this power comes at the price of a steep learning curve Drawing isn't intuitive; you can't sit down for a few minutes with the online Help text and start drawing graphics After you learn the basic principles involved, you'll find that drawing isn't that complicated In this hour, you'll learn the basic skills for drawing shapes and text to a form or other graphical surface You'll learn about pens, colors, and brushes (objects that help define graphics that you draw) In addition, you'll learn how to persist graphics on a formand even how to create bitmaps that exist solely in memory The highlights of this hour include the following: Understanding the Graphics object Working with pens Using system colors Working with rectangles Drawing shapes Drawing text Persisting graphics on a form Appendix A The 10,000-Foot View You know a lot about Visual C# NET by now You can create projects, use forms and controls to build an interface, and you know how to add menus and toolbars to a form You've also learned how to create modules and procedures and how to write code to make things happen You can use variables, make decisions, perform looping, and even debug your code The question you may be asking now is, "Where to next?" Throughout this book, I've focused my discussions on Visual C# NET When it comes to Microsoft's NET platform, however, Visual C# NET is just part of the picture In this appendix, I provide an overview of Microsoft's NET platform so that you can see how Visual C# NET relates to NET as a whole After you finish reading this appendix, you'll understand the various pieces of NET and how they're interrelated Hopefully, you'll be able to combine this information with your current personal and professional needs to determine the facets of NET that you want to explore in more detail Hour 1 Jumping in with Both Feet: A Visual C# NET Programming Tour Learning a new programming language can be intimidating If you've never programmed before, the act of typing seemingly cryptic text to produce sleek and powerful applications probably seems like a black art, and you may wonder how you'll ever learn everything you need to know The answer is, of course, one step at a time The first step to learning a language is the same as that of any other activitybuilding confidence Programming is part art and part science Although it may seem like magic, it's more akin to illusion; after you know how things work, a lot of the mysticism goes away, freeing you to focus on the mechanics necessary to produce the desired result In this hour, you'll complete a quick tour that takes you stepby-step through creating a complete, albeit small, Visual C# NET program I've yet to see a "Hello World" program that's the least bit helpful (they usually do nothing more than print "hello world" to the screenoh, fun) So instead, you'll create a picture-viewer application that lets you view Windows bitmaps and icons on your computer You'll learn how to let a user browse for a file and how to display a selected picture file on the screen Both of these skills will come in handy in the realworld applications that you'll create Producing large, commercial solutions is accomplished by way of a series of small steps After you've finished creating the project in this hour, you'll have an overall feel for the development process and will have taken the first step toward becoming an accomplished programmer The highlights of this hour include the following: Learning about the Visual Studio NET IDE Getting familiar with some programming lingo Building a simple (yet functional) Visual C# NET application Using a standard dialog box in your application to let the user browse a hard drive Adding a control to your application that enables the user to display a picture from a file on disk I hope that by the end of this hour, you'll realize just how much fun it is to program using Visual C# NET Hour 2 Navigating Visual Studio NET The key to expanding your knowledge of Visual C# NET is to become as comfortable as possibleas quickly as possiblewith the Visual Studio NET design environment Just as a carpenter doesn't think much about hammering a nail into a piece of wood, you can become so familiar with performing actions such as saving projects, creating new forms, and setting object properties that they'll be second nature to you The more comfortable you are with the tools of Visual Studio NET, the more you can focus your energies on what you're creating with the tools In this hour, you'll learn how to customize your design environment by moving, docking, floating, hiding, and showing design windows, as well as how to customize menus and toolbars You'll even create a new toolbar from scratch After you've gotten acquainted with the environment, I'll teach you about projects and the files that they're made of (taking you beyond what was briefly discussed in Hour 1, "Jumping in with Both Feet: A Visual C# NET Programming Tour"), and I'll introduce you to the design windows with which you'll work most frequently Finally, I'll show you how to get help when you're stuck The highlights of this hour include the following: Navigating Visual Studio NET Using the Visual Studio NET Start Page to open and create projects Showing, hiding, docking, and floating design windows Customizing menus and toolbars Adding controls to a form using the toolbox Viewing and changing object attributes using the Properties window Working with the many files that make up a project How to get help Hour 10 Creating and Calling Methods If you've been reading this book from the beginning, you've now spent about nine hours building the basic skills necessary to navigate Visual C# NET and to create an application interface Creating a good interface is extremely important, but it's only one step toward creating a Windows program After you've created the basic interface of an application, you need to enable the program to do something The program may perform an action all on its own, or it may perform actions based on a user interacting with the interfaceeither way, you write Visual C# NET code to make your application perform tasks In this hour, you'll learn how to create sets of code (called classes), and how to create and call isolated code routines (called methods) The highlights of this hour include the following: Creating static class members Creating methods Calling methods Exiting methods Passing parameters Avoiding recursive methods Working with tasks Hour 8 Using Advanced Controls The standard controls presented in the preceding hour enable you to build many types of functional forms However, to create truly robust and interactive applications, you've got to use the more advanced controls As a Windows user, you've encountered many of these controls, such as the Tab control, which presents data in tabbed dialog boxes, and the Tree View control, which displays hierarchical lists such as the one in Explorer In this hour, you'll learn about these advanced controls and learn how to use them to make professional interfaces like those you're accustomed to seeing in commercial products The highlights of this hour include the following: Creating timers Creating tabbed dialog boxes Storing pictures in an Image List control Building enhanced lists using the List View control Creating hierarchical lists with the Tree View control In many of the examples in this hour, I show you how to add items to collections at design time Keep in mind that almost everything you can do at design time can also be accomplished using Visual C# NET code at runtime Part III: Making Things HappenProgramming HOUR 11 Using Constants, Data Types, Variables, and Arrays HOUR 12 Performing Arithmetic, String Manipulation, and Date/Time Adjustments HOUR 13 Making Decisions in Visual C# Code HOUR 14 Looping for Efficiency HOUR 15 Debugging Your Code HOUR 16 Designing Object Using Classes HOUR 17 Interacting with Users HOUR 18 Working with Graphics ... 3rd check marks checked menu items 2nd checked menu items 2nd checking existence of directories existence of files 2nd chr prefix circles drawing class members creating 2nd 3rd 4th class modules... project component Class Programming Example application binding 2nd early binding 2nd 3rd late binding 2nd constructor methods 2nd object instantiation 2nd 3rd object interface creating... XML (eXtensible Markup Language) tags casting data types 2nd explicit casting implicit casting safe conversions 2nd catch statement 2nd 3rd 4th catching exceptions 2nd 3rd 4th categorical displays Properties window Categorized button (Properties window)