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

Ebook Visual C#® for kids (15th edition): Part 1

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 (4.48 MB, 209 trang )


VisualC#đ ForKids


15thEdition

By
PhilipConrod&LouTylee

â2017KidwareSoftwareLLC

KidwareSoftwareLLC
POBox701
MapleValley,WA98038




Copyright©2017byKidwareSoftwareLLC.Allrightsreserved
KidwareSoftwareLLC
POBox701
MapleValley,Washington98038
1.425.413.1185
www.kidwaresoftware.com
www.computerscienceforkids.com
AllRightsReserved.Nopartofthecontentsofthisbookmaybereproducedortransmittedinanyformor
byanymeanswithoutthewrittenpermissionofthepublisher.
PrintedintheUnitedStatesofAmerica
ISBN-13:978-1-937161-62-0(electronicedition)
978-1-937161-70-5(printededition)
Previouseditionpublishedas“VisualC#ExpressForKids–12thEdition”


CoverDesignbyStephanieConrod
CopyEditbyJessicaConrod
IllustrationsbyKevinBrockschmidt
Thiscopyof“VisualC#ForKids”andtheassociatedsoftwareislicensedtoasingleuser.Copiesofthe
course are not to be distributed or provided to any other user. Multiple copy licenses are available for
educationalinstitutions.PleasecontactKidwareSoftwareforschoolsitelicenseinformation.
This guide was developed for the course, “Visual C# For Kids,” produced by Kidware Software, Maple
Valley,Washington.ItisnotintendedtobeacompletereferencetotheVisualC#language.Pleaseconsult
theMicrosoftwebsitefordetailedreferenceinformation.
Thisguidereferstoseveralsoftwareandhardwareproductsbytheirtradenames.Thesereferencesarefor
informationalpurposesonlyandalltrademarksarethepropertyoftheirrespectivecompaniesandowners.
Microsoft,VisualStudio,SmallBasic,VisualBasic,VisualJ#,andVisualC#,IntelliSense,Word,Excel,
MSDN,andWindowsarealltrademarkproductsoftheMicrosoftCorporation.Javaisatrademarkproduct
oftheOracleCorporation.
The example companies, organizations, products, domain names, e-mail addresses, logos, people, places,
and events depicted are fictitious. No association with any real company, organization, product, domain
name,e-mailaddress,logo,person,place,oreventisintendedorshouldbeinferred.


Thisbookexpressestheauthor’sviewsandopinions.Theinformationinthisbookisdistributedonan"as
is"basis,withoutandexpresses,statutory,orimpliedwarranties.
Neithertheauthor(s)norKidwareSoftwareLLCshallhaveanyliabilitytoanypersonorentitywithrespect
toanylossnordamagecausedorallegedtobecauseddirectlyorindirectlybytheinformationcontainedin
thisbook.


AboutTheAuthorsPhilipConrodhasauthored,co-authoredandedited
numerouscomputerprogrammingbooksforkids,teensandadults.PhilipholdsaBSinComputer
InformationSystemsandaMaster'scertificateintheEssentialsofBusinessDevelopmentfromRegis
University.HealsoholdsaCertificateinProgrammingforBusinessfromWarrenTech.Philiphasbeen

programmingcomputerssince1977.HehasalsoheldvariousInformationTechnologyleadershiprolesin
companieslikeSundstrandAerospace,SafecoInsuranceCompanies,FamilyLife,KenworthTruck
Company,PACCARandDarigoldInc.Inhissparetime,PhilipservesasthePresident&Publisherof
KidwareSoftware,LLC.Heistheproudfatherofthree“techie”daughtersandlivesinMapleValley,
Washington.

LouTylee holdsBSandMSdegreesinMechanicalEngineeringandaPhDinElectricalEngineering.Lou
has been programming computers since 1969 when he took his first Fortran course in college. He has
writtensoftwaretocontrolsuspensionsforhighspeedgroundvehicles,monitornuclearpowerplants,lower
noiselevelsincommercialjetliners,computetakeoffspeedsforjetliners,locateandidentifyairandground
trafficandtoletkidscountbunnies,learnhowtospellanddomathproblems.HehaswrittenseveralonlinetextsteachingVisualBasic,VisualC#andJavatothousandsofpeople.HetaughtabeginningVisual
Basiccourseforover15yearsatamajoruniversity.Currently,LouworksasanengineeratamajorSeattle
aerospacefirm.Heistheproudfatheroffivechildrenandproudhusbandofhisspecialwife.Louandhis
familyliveinSeattle,Washington.


Acknowledgements
I want to thank my three wonderful daughters - Stephanie, Jessica and Chloe, who helped with various
aspectsofthebookpublishingprocessincludingsoftwaretesting,bookediting,creativedesignandmany
othermoretedioustaskslikefindingerrorsandtypos.Icouldnothaveaccomplishedthiswithoutallyour
hardwork,loveandsupport. IwanttoalsothankmybestfriendJesus,whohasalwaysbeentherebymy
sidegivingmewisdomandguidance.Withoutyou,thisbookwouldhaveneverbeenprintedandpublished.
Ialsowanttothankmymulti-talentedco-author,LouTylee,fordoingalltherealhardworknecessaryto
develop,test,debug,andkeepcurrentallthe‘beginner-friendly’applications,gamesandbasetutorialtext
found in this book. Lou has tirelessly poured his heart and soul into so many previous versions of this
tutorialandtherearesomanybeginnerswhohavebenefitedfromhisworkovertheyears.Louisbyfarone
of the best application developers and tutorial writers I have ever worked with. Thank you Lou for
collaboratingwithmeonthisbookproject.





TableofContents
CourseDescription
CoursePrerequisites
ABriefWordontheCourse
InstallingandUsingtheDownloadableSolutionFiles
UsingVisualC#ForKids
HowToTaketheCourse
ForwardbyAlanPayne,AComputerScienceTeacher

1.IntroducingVisualC#
AStoryAboutBillandPaul
Let’sGetStarted
StartingVisualC#
OpeningaVisualC#Project
RunningaVisualC#Project
StoppingaVisualC#Project
StoppingVisualC#
Summary

2.TheVisualC#DesignEnvironment


ReviewandPreview
PartsofaVisualC#Project
PartsoftheVisualC#Environment
StartingaNewVisualC#Project
MainWindow
SolutionExplorerWindow

DesignWindow
ToolboxWindow
PropertiesWindow
MovingAroundinVisualC#
SolutionExplorerWindow
PropertiesWindow
CodeWindow
Summary

3.YourFirstVisualC#Project
ReviewandPreview
StepsinBuildingaVisualC#Project
PlacingControlsontheForm
Example
SettingControlProperties(DesignMode)
NamingControls


SettingPropertiesinRunMode
HowControlNamesareUsedinEventMethods
WritingEventMethods
Example
Summary

4.ProjectDesign,Forms,Buttons
ReviewandPreview
ProjectDesign
SavingaVisualC#Project
On-LineHelp
TheFormControl

Properties
Example
Events
TypicalUseofFormControl
ButtonControl
Properties
Example
Events
TypicalUseofButtonControl
C#-TheFirstLesson


EventMethodStructure
SomeC#ProgrammingRules
AssignmentStatement
PropertyTypes
Comments
Project-FormFun
ProjectDesign
PlaceControlsonForm
SetControlProperties
WriteEventMethods
RuntheProject
OtherThingstoTry
Summary

5.Labels,TextBoxes,Variables
ReviewandPreview
DebuggingaVisualC#Project
SyntaxErrors

Run-TimeErrors
LogicErrors
LabelControl
Properties


Example
Events
TypicalUseofLabelControl
TextBoxControl
Properties
Example
Events
TypicalUseofTextBoxControl
C#-TheSecondLesson
Variables
VariableNames
VariableTypes
DeclaringVariables
TypeCasting
ArithmeticOperators
String/NumberConversionMethods
StringConcatenation
Project-SavingsAccount
ProjectDesign
PlaceControlsonForm
SetControlProperties


WriteEventMethods

RuntheProject
OtherThingstoTry
Summary

6.UpDownControl,Decisions,RandomNumbers
ReviewandPreview
NumericUpDownControl
Properties
Example
Events
TypicalUseofNumericUpDownControl
C#-TheThirdLesson
LogicalExpressions
ComparisonOperators
LogicalOperators
Decisions-TheIfStatement
RandomNumberGenerator
Project-GuesstheNumberGame
ProjectDesign
PlaceControlsonForm
SetControlProperties


WriteEventMethods
RuntheProject
OtherThingstoTry
Summary

7.Icons,GroupBoxes,CheckBoxes,Radio
Buttons

ReviewandPreview
Icons
CustomIcons
AssigningIconstoForms
GroupBoxControl
Properties
PlacingControlsinaGroupBox
Example
TypicalUseofGroupBoxControl
CheckBoxControl
Properties
Example
Events
TypicalUseofCheckBoxControl
RadioButtonControl


Properties
Example
Events
TypicalUseofRadioButtonControl
C#-TheFourthLesson
Decisions–SwitchStructure
Project-SandwichMaker
ProjectDesign
PlaceControlsonForm
SetControlProperties
WriteEventMethods
RuntheProject
OtherThingstoTry

Summary

8.Panels,MouseEvents,Colors
ReviewandPreview
PanelControl
Properties
TypicalUseofPanelControl
GraphicsUsingthePanelControl
GraphicsMethods


GraphicsObjects
Colors
Example
PenObjects
GraphicsCoordinates
DrawLineMethod
GraphicsReview
Example
C#-TheFifthLesson
MouseEvents
MouseDownEvent
Example
MouseUpEvent
Example
MouseMoveEvent
Example
Project-BlackboardFun
ProjectDesign
PlaceControlsonForm

SetControlProperties
WriteEventMethods


RuntheProject
OtherThingstoTry
Summary

9.PictureBoxes,Arrays
ReviewandPreview
PictureBoxControl
Properties
ImageProperty
Example
SizeModeProperty
Example
Events
TypicalUseofPictureBoxControl
C#-TheSixthLesson
VariableArrays
C#forLoops
BlockLevelVariables
MethodLevelVariables
ShuffleRoutine
Project-CardWars
ProjectDesign


PlaceControlsonForm
SetControlProperties

WriteEventMethods
RuntheProject
OtherThingstoTry
Summary

10.Timers,Animation,KeyboardEvents
ReviewandPreview
TimerControl
Properties
Events
Examples
TypicalUseofTimerControl
C#-TheFinalLesson
Animation-TheDrawImageMethod
ImageDisappearance
BorderCrossing
ImageErasure
CollisionDetection
KeyboardEvents
KeyDownEvent


KeyPressEvent
Project–BeachBalls
ProjectDesign
PlaceControlsonForm
SetControlProperties
WriteEventMethods
RuntheProject
OtherThingstoTry

Summary

BonusProjects
Preview
Project1–Stopwatch
ProjectDesign
PlaceControlsonForm
SetControlProperties
WriteEventMethods
RuntheProject
OtherThingstoTry
Project2-Tic-Tac-Toe
ProjectDesign
PlaceControlsonForm


SetControlProperties
WriteEventMethods
RuntheProject
OtherThingstoTry
Project3-DiceRolling
ProjectDesign
PlaceControlsonForm
SetControlProperties
WriteEventMethods
RuntheProject
OtherThingstoTry
Project4-StateCapitals
ProjectDesign
PlaceControlsonForm

SetControlProperties
WriteEventMethods
RuntheProject
OtherThingstoTry
Project5-MemoryGame
ProjectDesign
PlaceControlsonForm


SetControlProperties
WriteEventMethods
RuntheProject
OtherThingstoTry
BonusProject–Pong!

MoreSelf-StudyorInstructor-LedComputer
ProgrammingTutorialsbyKidwareSoftware


CourseDescription:VisualC#forKidsisaninteractive,self-paced
tutorialprovidingacompleteintroductiontotheVisualC#programming
languageandenvironment.Thetutorialconsistsof10lessonsexplaining(in
simple,easy-to-followterms)howtobuildaVisualC#application.Numerous
examplesareusedtodemonstrateeverystepinthebuildingprocess.Thetutorial
alsoincludesdetailedcomputerprojectsforkidstobuildandtry.VisualC#for
Kidsispresentedusingacombinationofcoursenotes(writteninMicrosoft
Wordformat)andmanyVisualC#examplesandprojects.


CoursePrerequisites:TouseVisualC#forKids,youshouldbe

comfortableworkingwithintheWindowsenvironment,knowinghowtofind
files,movewindows,resizewindows,etc.Noprogrammingexperienceis
needed.Thecoursematerialshouldbeunderstandabletokidsaged10andup.
YouwillalsoneedtheabilitytoviewandprintdocumentssavedinAdobe
Acrobatformat.

SoftwareRequirementsTouseVisualC#,youneedtohavethe
VisualStudio2015CommunityEditionproductinstalledonyourcomputer.Itis
availableforfreedownloadfromMicrosoft.Followthislinkforcomplete
instructionsfordownloadingandinstallingVisualStudio2015Comminity
Editiononyourcomputer: />

ABriefWordontheCourse:Thoughthiscourseisentitled
“VisualC#forKids,”itisnotnecessarilywritteninakid’svocabulary.
Computerprogramminghasadetailedvocabularyofitsownand,sinceadults
developedit,theterminologytendstobeveryadult-like.Indevelopingthis
course,wediscussedhowtoaddressthisproblemanddecidedwewouldtreat
ourkidreaderslikeadults,sincetheyarelearningwhatisessentiallyanadult
topic.Wedidnotwantto‘dumb-down’thecourse.Youseethisinsomebooks.
We,quitefrankly,areoffendedbybooksthatrefertoreadersasdummiesand
idiotssimplybecausetheyarenewtoaparticulartopic.Wedidn’twanttodo
thathere.Throughoutthecourse,wetreatthekidreaderasamatureperson
learninganewskill.Thevocabularyisnotthatdifficult,buttheremaybetimes
thekidreaderneedsalittlehelp.Hopefully,thenearestadultcanprovidethat
help.


InstallingandUsingtheDownloadableSolutionFiles:
Ifyoupurchasedthisdirectlyfromourwebsiteyoureceivedanemailwitha
specialandindividualizedinternetdownloadlinkwhereyoucoulddownloadthe

compressedProgramSolutionFiles.Ifyoupurchasedthisbookthrougha3rd
PartyBookStorelikeAmazon.com,thesolutionsfilesforthistutorialare
includedinacompressedZIPfilethatisavailablefordownloaddirectlyfrom
ourwebsiteat: />Completetheonlinewebformatthewebpageabovewithyourname,shipping
address, email address, the exact title of this book, date of purchase, online or
physicalstorename,andyourorderconfirmationnumberfromthatstore.After
wereceiveallthisinformationwewillemailyouadownloadlinkfortheSource
CodeSolutionFilesassociatedwiththisbook.
Warning: If you purchased this book “used” or “second hand” you are not
licensedorentitledtodownloadtheProgramSolutionFiles.However,youcan
purchasetheDigitalDownloadVersionofthisbookatadiscountedpricewhich
allows you access to the digital source code solutions files required for
completingthistutorial.


UsingVisualC#forKids:ThecoursenotesandcodeforVisualC#
forKidsareincludedinoneormoreZIPfiles.Useyourfavorite‘unzipping’
applicationtowriteallfilestoyourcomputer.Thecourseisincludedinthe
folderentitledVCSKids.Thisfoldercontainstwootherfolders:VCSKNotes
andVCSKProjects.TheVCSKProjectsfolderincludesalltheVisualC#
projectsdevelopedduringthecourse.


×