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

Teach yourself microsoft visual c sharp NET 2003 in 24 hours

786 76 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 786
Dung lượng 12,16 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

casting 2nd explicit implicit safe conversions 2nd char Common Type System 2nd DateTime 2nd 3rd... To make code more self-documenting always an importantgoal and to reduce the cha

Trang 1

[ 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 ]

Trang 2

creating 2nd 3rd 4th 5th

disposing of 2nd

methods 2nd 3rd 4th 5th 6th 7th 8th 9th 10th instantiating 2nd 3rd 4th 5th 6th

Trang 4

Like the book? Buy it!

Trang 5

[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 ]

Trang 6

[ 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 ]

Trang 7

OleDbDataAdapter object 2nd 3rd records

Trang 12

[ 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 ]

Trang 15

[ 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 ]

Trang 18

properties

colors

background

modifying in forms 2nd 3rd properties

Common Language Runtime (CLR) 2nd installing

Trang 20

Open File Dialog 2nd 3rd 4th 5th

Panel 2nd 3rd

Picture Viewer project

Button 2nd

Trang 24

[ 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 ]

Trang 25

navigating records 2nd 3rd 4th 5th running 2nd

DataRows 2nd

DataTables

adding records to 2nd 3rd 4th creating 2nd

deleting records from 2nd

editing records in

navigating 2nd 3rd 4th 5th disconnecting from 2nd

DataRows 2nd

DataTables

adding records to 2nd 3rd 4th creating 2nd

compile errors 2nd 3rd 4th

Trang 28

creating 2nd 3rd

custom dialog boxes 2nd 3rd 4th 5th Customize

file properties 2nd

attributes 2nd 3rd

code listing 2nd 3rd 4th 5th time/date information 2nd

icons 2nd 3rd 4th

MeesageBox.Show() method 2nd properties 2nd 3rd 4th

Trang 30

[ 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 ]

Trang 31

event procedures

Events Example application

event handler creation 2nd 3rd testing 2nd

starting Excel 2nd

testing

Trang 33

[ 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 ]

Trang 34

XML (eXtensible Markup Language) tags formatting

Trang 37

Web Forms;graphics

Web Forms;responsiveness

Web Forms;security

Web Forms;text formatting 2nd XML Web services 2nd 3rd

FromImage() method

[ Team LiB ]

Trang 38

[ 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 ]

Trang 41

hierarchical list creation 2nd removing nodes (Tree View)

[ Team LiB ]

Trang 42

[ 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 ]

handlers

events

deleting 2nd

handling errors [See error handling ]

handling events [See event handling ]

Trang 43

[ 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 ]

Trang 45

defined

forms

designing 2nd 3rd 4th 5th

writing code 2nd 3rd 4th 5th 6th 7th 8th 9th properties

iteration [See loops ]

iterative processing [See loops ]

[ Team LiB ]

Trang 46

[ 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 ]

Trang 47

[ 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 ]

Trang 48

[ 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 ]

Trang 50

rescursive loops when to use while loops 2nd

[ Team LiB ]

Trang 51

[ 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 ]

Trang 52

MDI Example application 2nd 3rd 4th 5th members

Trang 55

multiplication (*) operator

[ Team LiB ]

Trang 56

[ 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 ]

Trang 57

NewRow() method

No value (DialogResult) nodes (trees)

Trang 58

[ 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 ]

Trang 63

[ 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 ]

question mark (?)

Question value (MessageBoxIcon)

quitting [See exiting ]

[ Team LiB ]

Trang 64

[ 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 ]

Trang 66

[ 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 ]

Trang 67

SERVER= parameter (ConnectionString property) servers

Trang 70

System.Xml namespace SystemColors class properties

[ Team LiB ]

Trang 71

[ 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 ]

Trang 72

DialogResult enumeration 2nd displaying 2nd

guidelines 2nd

icons 2nd 3rd 4th

printing on Graphics object 2nd strings

Events Example application

Location

maximum length of 2nd

Method Example application 2nd multiline text boxes 2nd 3rd 4th password fields

properties

Enabled 2nd

MaxLength 2nd

Multiline

Trang 73

throwing exceptions

time/date information

adding time to 2nd

DateTime data type 2nd 3rd files 2nd

formatting 2nd

retrieving current date/time retrieving parts of 2nd

Trang 75

casting 2nd

explicit

implicit

safe conversions 2nd char

Common Type System 2nd DateTime 2nd 3rd

Trang 76

[ 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 ]

Trang 77

[ 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 ]

Trang 79

control additions to forms 2nd

void keyword

[ Team LiB ]

Trang 80

[ 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 ]

Trang 81

writing [See creating ]

[ Team LiB ]

Trang 82

[ 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 ]

Trang 83

[ 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 ]

Trang 84

[ 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]

Trang 85

To make code more self-documenting (always an importantgoal) and to reduce the chance of programming errors, youneed an easy way to determine the exact data type of a

variable or the exact type of a referenced control in Visual C#.NET code

Variable naming conventions have long been a hot topicsome find them beneficial while others don't.

Please be aware that using a naming convention is optional; if you don't like naming conventions, you don't have to use them.

Trang 86

Integer int intLoopCounter

The prefix of obj should be reserved for situations when a specific prefix isn't available The most common use of this prefix is when referencing Automation libraries of COM applications For instance, when automating Microsoft Word, you create an instance of Word's Application object.

Because no prefix exists specifically for Word objects, obj works just fine That is,

Word.Application objWord = new Word.Application;.

Denoting Scope Using Variable Prefixes

Prefixes are useful not only to denote data types, they also can

be used to denote scope (see Table 11.4) In particularly largeapplications, a scope designator is almost a necessity Again,Visual C# NET doesn't care whether you use prefixes, but

consistently using prefixes benefits you as well as others whohave to review your code

Table 11.4 Prefixes for Variable Scope

Trang 87

throughout this book.

Trang 88

Figure 3.10 The Object Browser enables you to view all properties and methods of an object.

The Browse drop-down list in the upper-left corner of the Object

Browser is used to determine the browsing scope You can

choose Active Project to view only the objects referenced in theactive project, or you can choose Selected Components (the

Trang 89

recommend changing the custom object setting until you havesome experience using Visual C# NET objects as well as

experience using the Object Browser

The top-level nodes in the Objects tree are libraries Libraries

are usually DLL or EXE files on your computer that contain one

or more objects To view the objects within a library, simplyexpand the library node As you select objects within a library,the list to the right of the Objects tree will show informationregarding the members of the selected object (refer to Figure3.10) For even more detailed information, click a member inthe list on the right, and the Object Browser will show

information about the member in the gray area below the twolists

Trang 90

In any programming language, the compiler, the part of theVisual Studio NET Framework that interprets the code you

write into a language the computer can understand, must fullyunderstand the type of data you're manipulating in code Forexample, if you asked the compiler to add the following values,

it would get confused:

659 / "Dog"

When the compiler gets confused, it either refuses to compilethe code (which is the preferred situation because you can

address the problem before your users run the application), or

it halts execution and displays an exception (error) when it

reaches the confusing line of code (These two types of errorsare discussed in detail in Hour 15, "Debugging Your Code.")Obviously, you can't divide 659 by the word "Dog"; these twovalues are different types of data In Visual C# NET, these two

Trang 91

constant, a variable, or an array at the time you define it VisualC# NET supports two categories of data types: value types andreference types The main difference between these two types

is how their values are stored in memory As you continue tocreate more complex applications, this difference may have animpact on your programming For this book, however, this

distinction is minimal Table 11.1 lists the Visual C# NET datatypes and the range of values each one can contain

double 1.79769313486232E308 to 4.94065645841247E-324 for negative

values; 4.94065645841247E324 to 1.79769313486232E308 for positive values

Trang 92

unless you have a very good reason for doing otherwise (such

as declaring a variable that will never hold a negative value)

Trang 93

The list of data types may seem daunting at first, but you can follow some

general guidelines for choosing among them As you become more familiar with the different types, you'll be able to fine-tune your data type selection.

If you need to store numbers that contain decimal places, use the float data type The float data type should work for almost all your values

containing decimals, unless you're writing incredibly complex mathematical applications or need to store very large numbers; in that case, use a

double.

If you need to store currency amounts, use the decimal data type.

To store a single character, use the char data type.

If you need to store a date and/or a time value, use the Date data type When you use the Date data type, Visual C# NET recognizes common date and time formats For example, if you store the value 7/22/2001, Visual C# NET doesn't treat it as a simple text string; it knows that the text

represents July 22, 2001.

Casting Data from One Data Type to Another

Trang 94

process of changing a value's data type is known as casting.

Visual C# NET supports two types of casting: implicit and

explicit Implicit conversions are done automatically by the

compiler These conversions guarantee that no data is lost inthe conversion For instance, you can set the value of a variabledeclared as double to the value of a variable declared as floatwithout an explicit cast because there is no risk of losing data;the double data type holds a more precise value than does a

float, and this type of cast is called a widening cast.

Explicit casting is required when a potential exists for data loss

or when converting a larger data type into a smaller data type(a narrowing cast) If you tried to place a value in a variablewhen the value was higher than the variable's supported datatype, some data would be lost Therefore, Visual C# NET

requires that these types of conversions be explicitly writtenusing the cast operator For instance, you can set the value of avariable declared as short to the value of a variable declared asinteger using the following syntax:

Table 11.2 Safe Conversions

Type Can Be Safely Converted To

Trang 96

The only way to really grasp what objects are and how theywork is to use them

You're about to create a sample project that uses objects Ifyou're new to programming with objects, you'll probably findthis a bit confusing However, I'll walk you through step by step,explaining each section in detail

The project you're going to create consists of a single form withone button on it When the button is clicked, a line will be

Trang 97

1 Double-click the button to access its Click event.

Enter the first line of code as follows (remember to pressEnter at the end of each statement):

System.Drawing.Graphics objGraphics = null;

Here you've just created a variable that will hold an instance of

an object Objects don't materialize out of thin air; they have to

be created When a form is loaded into memory, it loads all itscontrols (that is, creates the control objects), but not all objectsare created automatically like this The process of creating an

Ngày đăng: 25/03/2019, 16:33

TỪ KHÓA LIÊN QUAN