Tải bản đầy đủ (.pdf) (876 trang)

2002 sams teach yourself c sharp in 24 hours

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 (11.62 MB, 876 trang )

SamsTeachYourselfC#™in24Hours
ByJamesFoxallandWendyHaro-Chun

Table
Contents
About
Authors

of
the

Publisher:SamsPublishing
PubDate:March13,2002
ISBN:0-672-32287-0,528pages
Sams Teach Yourself C# in 24 Hoursprovides
readerswith24structuredlessonsthatprovide
alight,butthoroughintroductiontoC#.James
Foxall moves beyond the pure syntax covered
in existing books, to guide readers step-bystep through a cohesive presentation of the
basics of C#. Once the basics are understood,
Foxall shows the reader how to apply this
knowledge
to
real-world
Windows
programming tasks using C#. Each chapter
contains exercises that reinforce the lessons
learned in each chapter. Tips, Notes, and
Cautions provide additional advice from the
authors on how to get up to speed and
programming quickly with C#. Sidebars


provide the more experienced reader with tips
thatwilleasetheirmigrationfromVisualBasic
6andVisualC++toC#.


SamsTeachYourselfC#™in24Hours
Copyright
AbouttheAuthors
Acknowledgments
TellUsWhatYouThink!
Introduction
AudienceandOrganization
ConventionsUsedinThisBook
OnwardandUpward!

PartI.TheVisualStudioEnvironment
Hour1.AC#ProgrammingTour
StartingC#
CreatingaNewProject
UnderstandingtheC#Environment
ChangingtheCharacteristicsofObjects
NamingObjects
SettingtheTextPropertyoftheForm
GivingtheFormanIcon
ChangingtheSizeoftheForm
AddingControlstoaForm
DesigninganInterface
AddinganInvisibleControltoaForm
CodinganInterface
RunningaProject

Summary
Q&A
Workshop
Hour2.NavigatingC#
UsingtheVisualStudio.NETStartPage
NavigatingandCustomizingtheC#Environment


AddingControlstoaFormUsingtheToolbox
SettingObjectPropertiesUsingthePropertiesWindow
ManagingProjects
ManagingProjectFileswiththeSolutionExplorer
GettingHelp
Summary
Q&A
Workshop
Hour3.UnderstandingObjectsandCollections
UnderstandingObjects
UnderstandingProperties
UnderstandingMethods
BuildinganObjectExampleProject
UnderstandingCollections
UsingtheObjectBrowser
Summary
Q&A
Workshop
Hour4.UnderstandingEvents
UnderstandingEvent-DrivenProgramming
BuildinganEventExampleProject
Summary

Q&A
Workshop

PartII.BuildingaUserInterface
Hour5.BuildingForms—PartI
ChangingtheNameofaForm
ChangingtheAppearanceofaForm
ShowingandHidingForms
Summary
Q&A
Workshop


Hour6.BuildingForms—PartII
WorkingwithControls
CreatingTopMostWindows
CreatingTransparentForms
CreatingScrollableForms
CreatingMDIForms
SettingtheStartupObject
Summary
Q&A
Workshop
Hour7.WorkingwiththeTraditionalControls
DisplayingStaticTextwiththeLabelControl
AllowingUserstoEnterTextUsingaTextBox
CreatingButtons
CreatingContainersandGroupsofOptionButtons
DisplayingaListwiththeListBox
CreatingDrop-DownListsUsingtheComboBox

Summary
Q&A
Workshop
Hour8.AdvancedControls
CreatingTimers
CreatingTabbedDialogBoxes
StoringPicturesinanImageList
BuildingEnhancedListsUsingtheListView
CreatingHierarchicalListswiththeTreeView
Summary
Q&A
Workshop
Hour9.AddingMenusandToolbarstoForms
BuildingMenus
ProgrammingMenus
UsingtheToolbarControl
CreatingaStatusBar


Summary
Q&A
Workshop
Hour10.DrawingandPrinting
UnderstandingtheGraphicsObject
WorkingwithPens
UsingSystemColors
WorkingwithRectangles
DrawingShapes
DrawingText
PersistingGraphicsonaForm

BuildaGraphicsProjectExample
Summary
Q&A
Workshop

Part
III.
Making
Programming!

Things

Happen—

Hour11.CreatingandCallingMethods
CreatingClassMembers
WritingMethods
CreatingtheUserInterfaceofYourProject
CallingMethods
ExitingMethods
WorkingwithTasks
Summary
Q&A
Workshop
Hour 12. Using Constants, Data Types, Variables,
andArrays
UnderstandingDataTypes
DefiningandUsingConstants
DeclaringandReferencingVariables
DeterminingScope



NamingConventions
Summary
Q&A
Workshop
Hour 13. Performing Arithmetic,
Manipulation,andDate/TimeAdjustments
PerformingBasicArithmetic
ComparingEqualities
UnderstandingBooleanLogic
ManipulatingStrings
WorkingwithDatesandTimes
Summary
Q&A
Workshop

String

Hour14.MakingDecisionsinC#Code
MakingDecisionsUsingifStatements
Evaluating an Expression for Multiple Values Using
switch
BranchingWithinCodeUsinggoto
Summary
Q&A
Workshop
Hour15.LoopingforEfficiency
Looping a Specific Number of Times Using for
Statements

Using do…while to Loop an Indeterminate Number of
Times
Summary
Q&A
Workshop
Hour16.DebuggingYourCode
AddingCommentstoYourCode
IdentifyingtheTwoBasicTypesofErrors


UsingC#'sDebuggingTools
Writing an

Error

Handler

Using

try...catch...finally
Summary
Q&A
Workshop
Hour17.DesigningObjectsUsingClasses
UnderstandingClasses
InstantiatingObjectsfromClasses
Summary
Q&A
Workshop
Hour18.InteractingwithUsers

Displaying Messages Using the MessageBox.Show()
Method
CreatingCustomDialogBoxes
InteractingwiththeKeyboard
UsingtheCommonMouseEvents
Summary
Q&A
Workshop

PartIV.WorkingwithData
Hour19.PerformingFileOperations
Using the Open File Dialog and Save File Dialog
Controls
ManipulatingFileswiththeFileObject
ManipulatingDirectorieswiththeDirectoryObject
Summary
Q&A
Workshop
Hour 20. Controlling Other Applications Using
Automation


CreatingaReferencetoanAutomationLibrary
CreatinganInstanceofanAutomationServer
ManipulatingtheServer
Summary
Q&A
Workshop
Hour21.WorkingwithaDatabase
IntroductiontoADO.NET

ConnectingtoaDatabase
ManipulatingData
UsingtheDataFormWizard
Summary
Q&A
Workshop

PartV.DeployingSolutionsandBeyond
Hour22.DeployingaSolution
CreatingaCustomSetupProgram
RunningaCustomSetupProgram
UninstallinganApplicationYou'veDistributed
Summary
Q&A
Workshop
Hour23.IntroductiontoWebDevelopment
XML
SOAP
ASP.NET
WebForms
XMLWebServices
Summary
Q&A
Workshop
Hour24.The10,000-FootView


The.NETFramework
CommonLanguageRuntime(CLR)
MicrosoftIntermediateLanguage

Namespaces
CommonTypeSystem
GarbageCollection
Summary
Q&A
Workshop
AppendixA.AnswerstoQuizzes/Exercises
AnswerstoHour1
AnswerstoHour2
AnswerstoHour3
AnswerstoHour4
AnswerstoHour5
AnswerstoHour6
AnswerstoHour7
AnswerstoHour8
AnswersforHour9
AnswerstoHour10
AnswerstoHour11
AnswerstoHour12
AnswerstoHour13
AnswerstoHour14
AnswerstoHour15
AnswerstoHour16
AnswerstoHour17
AnswerstoHour18
AnswersforHour19
AnswerstoHour20
AnswerstoHour21
AnswerstoHour22
AnswersforHour23

AnswersforHour24


Top






Copyright
Copyright©2002bySamsPublishing
All rights reserved. No part of this book shall be reproduced,
stored in a retrieval system, or transmitted by any means,
electronic, mechanical, photocopying, recording, or otherwise,
without written permission from the publisher. No patent
liability is assumed with respect to the use of the information
containedherein.Althougheveryprecautionhasbeentakenin
the preparation of this book, the publisher and author assume
no responsibility for errors or omissions. Nor is any liability
assumedfordamagesresultingfromtheuseoftheinformation
containedherein.
LibraryofCongressCatalogCardNumber:2001093572
PrintedintheUnitedStatesofAmerica
FirstPrinting:February2002
050403024321

Trademarks
All terms mentioned in this book that are known to be
trademarks or service marks have been appropriately

capitalized. Sams Publishing cannot attest to the accuracy of
this information. Use of a term in this book should not be
regarded as affecting the validity of any trademark or service
mark.

WarningandDisclaimer


Everyefforthasbeenmadetomakethisbookascompleteand
as accurate as possible, but no warranty or fitness is implied.
Theinformationprovidedisonan"asis"basis.Theauthorand
thepublishershallhaveneitherliabilitynorresponsibilitytoany
person or entity with respect to any loss or damages arising
fromtheinformationcontainedinthisbook.

Credits
AssociatePublisher
LindaEngelman
AcquisitionsEditor
SondraScott
DevelopmentEditor
GinnyBess
ManagingEditor
CharlotteClapp
ProjectEditor
CarolBowers
CopyEditor
BarbaraHacha
Indexer
ErikaMillen

Proofreader


JodyLarsen
TechnicalEditors
JoelMueller
DeonSchaffer
TeamCoordinator
LynneWilliams
MediaDeveloper
DanScherf
InteriorDesigner
GaryAdair
CoverDesigner
ArenHowell
PageLayout
D&GLimited,LLC

Dedication
Tomychildren,EthanandTess.
—JamesFoxall
Tomyparents,OlgaandAlfonso,andmylove,Dave.
—WendyHaro-Chun



Top








AbouttheAuthors
JamesFoxallisVicePresidentofDevelopmentandSupportfor
Tigerpaw Software, Inc. (www.tigerpawsoftware.com)—an
Omaha, Nebraska, Microsoft Certified Partner specializing in
commercial database applications. James manages a
commercial suite of programs designed to automate contact
management, marketing, service and repair, proposal
generation, and inventory control and purchasing. James's
experience in creating certified Office-compatible software has
made him an authority on application interface and behavior
standards of applications for the Microsoft Windows and
MicrosoftOfficeenvironments.
James has personally written more than 150,000 lines of
commercial production code, both in single programmer and
multiple programmer environments. He is the author of
numerous books, including Practical Standards for Microsoft
VisualBasic and MCSD in a Nutshell: The Visual Basic Exams,
and he has written articles for Access-Office-VBA Advisor and
Visual Basic Programmer's Journal. James is a Microsoft
Certified Solution Developer and an international speaker on
Microsoftprogrammingtechnologies.Whennotprogrammingor
writing about programming, he enjoys spending time with his
family, playing guitar, doing battle over the chess board,
listeningtoPinkFloyd,playingcomputergames,and(believeit
or not) programming! You can reach James at


WendyHaro-Chun, MCSD, holds a B.S. in Computer Science
andanM.B.A.withanemphasisinInternationalBusiness.She
is Assistant Vice President of Research and Development for
SunGard Insurance Systems. Her areas of technological
expertiseinclude.NET,C#,ASP,DHTML,JavaScript,XML,COM,
VB, ADO, and Microsoft SQL Server. Wendy has also served as


technical editor and reviewer on numerous computer
technology books. She lives in Miami with her husband, Dave,
and her two beagles, Buster and Belle. She can be reached at




Top







Acknowledgments
James'sacknowledgements:
ToSondraScott,bothfortheopportunitytodothisbookaswell
asjustbeingagreatpersontoworkfor!
ToWendyforherwonderfulcontributions,CarolBowers,Ginny
Bess,JoelMueller,DeonSchaffer,andeveryoneelsethathada
handinthisbook—thanksguys!

ToMattWagneratWatersideProductionsforallhishelpbehind
thescenes.
Tomywifeandchildrenforalwayssupportingandencouraging
methroughtheseprojects.Youarethebest!
Finally, a special thanks to Mike Pizzo at Microsoft for his
contributionstotheADO.NETchapter.
Wendy'sacknowledgements:
IwouldliketothankSondraScottforgivingmetheopportunity
to work on this great project. I would also like to thank Ginny
Bess and Carol Bowers for making sure everything came
together and technical editors Joel and Deon for making sure
this new technology worked the way I said it did. Also, special
thankstoPeterFarquharson,DavidMarcato,DeonSchaffer,and
Larry Wall for helping to get this project started on a good
foundation.
To James Foxall, I have enjoyed reading your VB .NET book,
and it has been a great pleasure working with you on this C#
book.
A big thanks goes out to my husband, Dave, for his constant
supportinallmyprojectsandforalwaysbelievinginme.


To Olga and Alfonso, thank you for all the support,
encouragement,andloveyouhavealwaysgivenme.
Finally, thanks to all my relatives and friends for buying this
book!



Top








TellUsWhatYouThink!
As the reader of this book, you are our most important critic
and commentator. We value your opinion and want to know
what we're doing right, what we could do better, what areas
you'dliketoseeuspublishin,andanyotherwordsofwisdom
you'rewillingtopassourway.
AsanAssociatePublisherforSamsPublishing,Iwelcomeyour
comments. You can fax, e-mail, or write me directly to let me
know what you did or didn't like about this book—as well as
whatwecandotomakeourbooksstronger.
Please note that I cannot help you with technical problems
related to the topic of this book, and that because of the high
volumeofmailIreceive,Imightnotbeabletoreplytoevery
message.
Whenyouwrite,pleasebesuretoincludethisbook'stitleand
author as well as your name and phone or fax number. I will
carefullyreviewyourcommentsandsharethemwiththeauthor
andeditorswhoworkedonthebook.
Fax:
E-mail:
Mail:

317-581-4770


LindaEngelman
SamsPublishing
201West103rdStreet
Indianapolis,IN46290USA




Top







×