Tải bản đầy đủ (.pdf) (1,957 trang)

Aw net compact framework programming with c sharp

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 (14.32 MB, 1,957 trang )

don'tbeafraidofbuyingbooks

Next

.NETCompactFrameworkProgramming
withC#
ByPaulYao,DavidDurant

Publisher :PrenticeHallPTR
PubDate :May24,2004
ISBN :0-321-17403-8
Pages :1424

.NETCompactFrameworkProgramming
withC#isthedefinitivetutorialand
referenceforthe.NETCompactFramework
(CF).Itshowsyouhowtotransferyourskills
andyourcodetothePocketPC2003and
othermobileandembeddedsmartdevices.
AuthorsPaulYaoandDavidDurantdrawupon
theiryearsofresearchandexperiencewith
membersoftheMicrosoft.NETCFteamto
showyouexactlyhowthebestCF
programminggetsdoneinC#.Thisisthe
onlybookaprogrammerneedstomasterthe
artofCFcoding.Throughoutthebook,
samplecodeandexamplesillustratebest
practicesandprogrammingtechniques.In
addition,thecompanionWebsiteincludes
downloadablecodeforalltheseexamples,
alongwithasetofdevelopmenttoolstohelp


youwithyourCFdevelopmentprojects.




Theauthorsexpertlyzeroinonwhat
programmersneedtounderstandfor


• Tableof successfulsmartdeviceprogramming,
Contents including:
GarbageCollectioninthe.NETCompact
Framework
ControlsandsupportedProperties,
Methods,andEvents(PMEs)
CustomcontrolswithWindowsForms
Designersupport
UsingPlatformInvoke(P/Invoke)
Simpleandcomplexdatabindingandthe
DataGridcontrol
ProgrammingwithADO.NETdataclasses
SynchronizingSQLServerCEwithSQL
Server2000databases
Creatinggraphicaloutput,includingfont
andprintingcodingtricks
Differencesbetweenthestandarddesktop
frameworkandtheCF
.NETCompactFrameworkProgramming
withC#isyoursingleresourcefor
everythingyoureallyneedtoknowaboutCF

programming.

Amazon


Prev

don'tbeafraidofbuyingbooks

Next

.NETCompactFrameworkProgramming
withC#



ByPaulYao,DavidDurant

Publisher :PrenticeHallPTR

Tableof PubDate :May24,2004

ISBN :0-321-17403-8
Contents
Pages :1424










Copyright
Praisefor.NETCompactFrameworkProgrammingwithC#
Microsoft.NETDevelopmentSeries
TitlesintheSeries
Foreword
Preface
WhatYouNeedtoUseThisBook

TheTargetAudienceforThisBook


Acknowledgments

AbouttheAuthors

PartI.Foundations
Chapter1..NETCompactFrameworkArchitecture




WindowsCEOverview





The.NETCompactFramework




WhatIs.NET?
CONCLUSION
Chapter2.WhatIsa.NETCompactFrameworkProgram?
TheEssenceofa.NETCompactFrameworkProgram




UsingVisualStudio.NET2003




AddingClasses






TheCisternSampleProgram
CONCLUSION
Chapter3.The.NETTypeSystem
UsingTypeInformation:NamespaceReferencesandAssemblyReferences
StandardTypes

Strings





TypeConversion




CONCLUSION

MemoryManagement
Chapter4.PlatformInvoke




OverviewofP/Invoke




SupportedP/InvokeFunctionParameters




WritingWin32DynamicLinkLibraries





CommunicatingbetweenUnmanagedandManagedCode

CreatingP/InvokeDeclarations
ASampleProgram:CallWin32
ManualP/InvokeParameterPassing
ComparingP/InvokeSupport

CONCLUSION


PartII.BuildingtheUserInterface
Chapter5.CreatingForms




WhatAreForms?




InheritanceandVisualInheritance





Chapter6.MouseandKeyboardInput

ManipulatingForms
CONCLUSION
OverviewofInput




ProgrammingforMouseInput




CONCLUSION

ProgrammingforKeyboardInput
Chapter7.InsideControls




WhatAreControls?




Properties,Methods,andEvents





TheCoreProperties




WorkingwithControlTypeInformation




ASampleProgram:TimeTracker




TheTextBoxControl




TheButtonControl

CategoriesofControls
TheCoreEvents
TheCoreMethods
FiveCommonlyUsedControls
TheLabelControl
TheListBoxandComboBoxControls

TheRadioButtonandCheckBoxControls






CONCLUSION
Chapter8.DataBindingtoControls
DataBinding




ComplexDataBinding




TheDataGridControl




SimpleDataBinding
CONCLUSION
Chapter9.InsideMoreControls
DetectingSupportforProperties,Methods,andEvents





Menus




TheToolBarandImageListControls




CONCLUSION

GrabbingEvents
DialogBoxes
Chapter10.BuildingCustomControls




CustomControls




DerivingCustomControlsfromanExisting.NETControl





CreatingNewControls




AuthoringCustomControlsfortheMultithreadedEnvironment

ControlsasObjects
CreatingCompositeControls
AddingAnimationtoaCustomControl
AddingaCustomControltotheVisualStudio.NETToolbox

CONCLUSION


PartIII.ManagingDeviceData
Chapter11.Storage




Smart-DeviceDataStorage




RegistryAccess





FileI/O
CONCLUSION
Chapter12.ADO.NETProgramming
ExaminingADO.NET




WorkingwithDataSets




MicrosoftSQLServer




CONCLUSION



MicrosoftSQLServerCE
WebServices
Chapter13.SynchronizingMobileData
UnderstandingRemoteDataApplications





InstallingRemoteDataConnectivity




UsingRDA




ChoosingbetweenMergeReplicationandRDA




UsingMergeReplication
CONCLUSION
Chapter14.TheRemoteAPI
WhatIsActiveSync?




RAPIFundamentals



DetectingChangesinDeviceConnectionState





LoadingProgramsandDLLs

AccessingtheObjectStore

CONCLUSION


PartIV.CreatingGraphicalOutput
Chapter15..NETCompactFrameworkGraphics

AnIntroductionto.NETCompactFrameworkGraphics




DrawingontheDisplayScreen




VectorGraphics




RasterGraphics

CONCLUSION
Chapter16.TextandFonts
DrawingText




FontSelection




TextColor




PlacingText
CONCLUSION
Chapter17.Printing
ThePrintingPipeline




ProgrammingforPrintedOutput





RenderingwithGDI




RenderingwithPrinterCE

DirectPrinting
HPMobilePrinting
CONCLUSION


PartV.Appendixes
AppendixA.HungarianNotationfor.NETPrograms

GoalsandObjectives




Guidelines



HungarianNotation

.NETNamingGuidelines





AppendixB.SupportedPMEsfor.NETCompactFrameworkControls



AppendixC.DataSynchronizationWizards






TheVirtualDirectoryCreationWizard
TheCreatePublicationWizard
AppendixD.WindowsAPIAllocationandCleanupFunctions
Glossary

Amazon


Prev

don'tbeafraidofbuyingbooks

Next


Copyright
Manyofthedesignationsusedbymanufacturersand
sellerstodistinguishtheirproductsareclaimedas

trademarks.Wherethosedesignationsappearinthisbook,
andAddison-Wesleywasawareofatrademarkclaim,the
designationshavebeenprintedwithinitialcapitallettersor
inallcapitals.
The.NETlogoiseitheraregisteredtrademarkor
trademarkofMicrosoftCorporationintheUnitedStates
and/orothercountriesandisusedunderlicensefrom
Microsoft.
Microsoft,Windows,VisualBasic,VisualC#,andVisual
C++areeitherregisteredtrademarkortrademarksof
MicrosoftCorporationintheU.S.A.and/orother
countries/regions.
Theauthorsandpublisherhavetakencareinthe
preparationofthisbook,butmakenoexpressedorimplied
warrantyofanykindandassumenoresponsibilityfor
errorsoromissions.Noliabilityisassumedforincidentalor
consequentialdamagesinconnectionwithorarisingoutof
theuseoftheinformationorprogramscontainedherein.
Thepublisheroffersdiscountsonthisbookwhenordered
inquantityforbulkpurchasesandspecialsales.Formore
information,pleasecontact:
U.S.CorporateandGovernmentSales
(800)382-3419

ForsalesoutsideoftheU.S.,pleasecontact:


InternationalSales
(317)581-3793


VisitAddison-WesleyontheWeb:
www.awprofessional.com
LibraryofCongressCataloging-in-PublicationData
Yao,Paul.
.NETcompactframeworkprogramming
withC#/PaulYao,DavidDurant.
p.cm.—(Microsoft.NETdevelopmentseries)
Includesindex.
ISBN0-321-17403-8(alk.paper)
1.C#(Computerprogramlanguage)
2.Microsoft.NETFramework.I.Durant,
David.II.Title.III.Series.
QA76.73.C154Y362004
005.13'3—dc22
2004002429
Copyright©2004byPearsonEducation,Inc.
Allrightsreserved.Nopartofthispublicationmaybe
reproduced,storedinaretrievalsystem,ortransmitted,in
anyform,orbyanymeans,electronic,mechanical,
photocopying,recording,orotherwise,withouttheprior
consentofthepublisher.PrintedintheUnitedStatesof
America.PublishedsimultaneouslyinCanada.
Forinformationonobtainingpermissionforuseofmaterial
fromthiswork,pleasesubmitawrittenrequestto:
PearsonEducation,Inc.
RightsandContractsDepartment
75ArlingtonStreet,Suite300


Boston,MA02116

FFax:(617)848-704
Textprintedonrecycledpaper
12345678910—CRW—0807060504
Firstprinting,May2004

Dedication
ForRebecca:mywife,mypartner,mybestfriend
—Paul
ToJohnandRuthDurant,whoseloveandcouragewerean
inspirationtotheirchildren
—David
Amazon


Prev

don'tbeafraidofbuyingbooks

Next


Praisefor.NETCompactFramework
ProgrammingwithC#
"Fornearlytwodecades,PaulYaoandDavidDurant
havebeenacknowledgedasexpertsontheWindows
platform,soit'sonlynaturalthattheywouldbring
theirexperiencedpointofviewtothe.NETCompact
Framework.Withauniquecombinationofhistorical
perspectiveandin-depthunderstandingofthesubject
matter,YaoandDuranttakethereaderthroughnot

onlythetechnicalgutsoftheCompactFrameworkbut
alsothereasonsbehindthedesigndecisions."
—JoshuaTrupin,ExecutiveEditor,MSDNMagazine
"YaoandDuranthavewrittenabookthat,althoughit
assumesnopriorexperiencewiththe.NETFramework,
servesboththerookieandadvancedprogrammer
equallywell.Thisisdefinitelyararequalityamong
technicalbooksandiscertainlynotaneasythingfor
anauthortoaccomplish."
—DougHolland,PrecisionObjects
"Thisisaverygoodhands-onbookwithplentyof
samplecodeillustratingprogrammingtasksand
techniques,whichanyseriousdevelopmenteffortfor
WindowsCEorPocketPCwillrequire."
—BillDraper,DirectorofSoftwareDevelopment
"Thisbookservesasbothagreatreferenceand
tutorialwhenbuilding.NETCompactFramework
applications.Myonlywishisthatithadbeenavailable
sooner."


—GregHack,SeniorSoftwareEngineer,Allscripts
HealthcareSolutions
"OfthehandfulofbooksonCompactFramework,this
booktakesthecake.PaulYaoandDavidDurant's
expertisewith.NETCompactFrameworkisevident
fromtheirexcellentandveryinsightfulcoverageof
sectionssuchasBuildingtheUserInterface,Managing
DeviceData,andCreatingGraphicalOutput.The
chapterdiscussingthetopicofP/Invokeis

unparalleled.Afterreviewingthisbook,Iamcertain
thatifthereisonebookthatwillhelpyouunderstand
.NETCompactFramework,thisistheone."
—DeepakSharma,SeniorSystemsSpecialist,Tata
InfotechLtd.
"YaoandDurant'sfresh,innovative,andin-depthlook
atthe.NETCompactFrameworkgetsdevelopersupto
speedusingC#todeveloprobustandscaleable
handheldsoftwaresolutions.Adefinitemust-readfor
mobilehandhelddeveloperenthusiasts!"
—AndrewKrowczyk,SoftwareArchitect,ZurichNorth
America
Amazon


Prev

don'tbeafraidofbuyingbooks

Next


Microsoft.NETDevelopmentSeries
JohnMontgomery,SeriesAdvisor
DonBox,SeriesAdvisor
MartinHeller,SeriesEditor
TheMicrosoft.NETDevelopmentSeriesissupported
anddevelopedbytheleadersandexpertsofMicrosoft
developmenttechnologiesincludingMicrosoftarchitects
andDevelopMentorinstructors.Thebooksinthisseries

provideacoreresourceofinformationandunderstanding
everydeveloperneedsinordertowriteeffective
applicationsandmanagedcode.Learnfromtheleaders
howtomaximizeyouruseofthe.NETFrameworkandits
programminglanguages.
Amazon


Prev

don'tbeafraidofbuyingbooks

Next

TitlesintheSeries
BradAbrams,.NETFrameworkStandardLibraryAnnotated
ReferenceVolume1,0-321-15489-4
KeithBallinger,.NETWebServices:Architectureand
Implementation,0-321-11359-4
BobBeauchemin,NielsBerglund,DanSullivan,AFirst
LookatSQLServer2005forDevelopers,0-321-18059-3
DonBoxwithChrisSells,Essential.NET,Volume1:The
CommonLanguageRuntime,0-201-73411-7
MaheshChand,GraphicsProgrammingwithGDI+,0-32116077-0
AndersHejlsberg,ScottWiltamuth,PeterGolde,TheC#
ProgrammingLanguage,0-321-15491-6
AlexHomer,DaveSussman,MarkFussell,AFirstLookat
ADO.NETandSystem.Xmlv.2.0,0-321-22839-1
AlexHomer,DaveSussman,RobHoward,AFirstLookat
ASP.NETv.2.0,0-321-22896-0

JamesS.MillerandSusannRagsdale,TheCommon
LanguageInfrastructureAnnotatedStandard,0-32115493-2
FritzOnion,EssentialASP.NETwithExamplesinC#,0201-76040-1
FritzOnion,EssentialASP.NETwithExamplesinVisual
Basic.NET,0-201-76039-8


TedPattisonandDr.JoeHummel,BuildingApplicationsand
ComponentswithVisualBasic.NET,0-201-73495-8
ChrisSells,WindowsFormsProgramminginC#,0-32111620-8
ChrisSellsandJustinGehtland,WindowsForms
ProgramminginVisualBasic.NET,0-321-12519-3
PaulVick,TheVisualBasic.NETProgrammingLanguage,
0-321-16951-4
DamienWatkins,MarkHammond,BradAbrams,
Programminginthe.NETEnvironment,0-201-77018-0
ShawnWildermuth,PragmaticADO.NET:DataAccessfor
theInternetWorld,0-201-74568-2
PaulYaoandDavidDurant,.NETCompactFramework
ProgrammingwithC#,0-321-17403-8
PaulYaoandDavidDurant,.NETCompactFramework
ProgrammingwithVisualBasic.NET,0-321-17404-6
Formoreinformationgoto
www.awprofessional.com/msdotnetseries/
Amazon


Prev

don'tbeafraidofbuyingbooks


Next


Foreword
Welcome,futuresmart-devicedeveloper!Todaywe
embarkonanexcitingjourney.Forthefirsttime,mobile
devicesareimpactingthelivesofusersinprofoundways.
Mobiledeviceshavebecomeaneverydayingredientinthe
livesofmillionsofpeoplearoundtheworld,whetherthey
aremobileemployeesworkingfromthefieldorcasual
consumersplayingthelatestandgreatestgames.For
example,myPocketPCPhoneEditionhasmorememory
andprocessingpowerthanthehigh-endPCIboughtfora
premiumnotevenfiveyearsago.Iusemymobiledevice
foreverythingfromhandlinge-mailandbrowsingtheWeb
toplayinggames,music,andvideos.Inmanyways,ithas
replacedtheheavylaptopIonceluggedfrommeetingto
meeting.
Atthesametime,theinnovationinthisspacehasdriven
theneedforcustomsoftwaredevelopment.Withnewer
andmorepowerfuldevicescomestheneedfornewerand
morepowerfulsoftwaredevelopmenttools.Drivingthis
phenomenon—asalways—isyou,thesoftwaredeveloper.
Toassistyou,MicrosoftisprovidingVisualStudio.NETand
the.NETCompactFramework,themostcapable
developmentandruntimeenvironmentsavailable,to
enableyoutomakethemostofopportunitieswithyour
customers,includingmobileemployees,casualconsumers,
andeventhemostuncompromisinglyrabiddevice

enthusiasts(ourauthors).
Sowhyhasmobiledevelopmentbecomesoimportantall
ofasudden?Well,asanyveterandevelopercantellyou,
mobiledevelopmenthasbeenaroundforalongtime.In
fact,theyoftenreminisceaboutthegoodolddaysof
developingwitheMbeddedVisualBasic.(Hey,sixmonths


isalongtimeinthesoftwareindustry!)Thetruthisthat
forthefirsttime,severaldrivingfactorsinthetechnology
ecosystemhavealignedtoprovidethesolidfoundation
mobile-devicedevelopersneedtogaintrueopportunities
intheconsumerandenterprisemarkets.
Thefirstandmostobviousfactordrivingthisphenomenon
istheintroductionofVisualStudio.NET2003andthe.NET
CompactFramework.Combined,thesetoolsprovidea
developmentpowerhousethatenablesyouasadeveloper
totakeadvantageofprogramminglanguagesandskills
youalreadyknowandusefordevelopingdesktop
applications,includingarichsubsetofclasslibrariesand
thesamesecure,managedenvironment.You'lllearnmore
aboutthisinPartI,Foundations.
ThenextmajorfactoristheMicroprocessorEffect(also
knownasMoore'sLaw),whichdescribestheregular
doublingofthenumberofcircuitsinmicroprocessors.At
present,circuitdoublingoccursaboutevery18months.In
reality,theadoptionofmoreprocessingpowerformobile
deviceshasexceededthegrowthsuggestedbyMoore's
Law.Butithasn'tbeenonlyincreasesinprocessingpower
thathaveexceededpredictions—increasesinthecapacity

ofothernecessarycomponents,suchasmemoryand
peripheralcapabilities,haveoccurredaswell.
Thecontinuedimprovementsinhardwarecapabilities
coupledwiththecontinueddecreaseinhardwarecosts
havecreatedanenvironmentthathasallowedforthe
proliferationofdifferenttypesofmobileandembedded
devices.Today,the.NETCompactFrameworksupports
softwaredevelopmentonthevariousgenerationsofthe
PocketPC,thePocketPCPhoneEdition,andtheMicrosoft
Smartphone.ItalsoprovidesgreatsupportforWindows
CE–poweredsmartdevicesthatrunWindowsCE.NET4.1
andlater.


Allofthisprovidesagreatenvironmentfordevelopersto
makethemostofclient-sidedevelopment.You'llbeableto
rapidlydesignapplicationsusingtheplethoraofcontrols
nativetothe.NETCompactFrameworkandcreatenew
controls,asyouwilllearnaboutinPartII,Buildingthe
UserInterface.Thegrowthindevicecapacitymeansthat
mobiledevicescanhaveenoughlocalstoragetocollect
significantvolumesofdata,evenwhendisconnected—a
subjectcoveredinthisbookinPartIII,ManagingDevice
Data.Theaddedhorsepoweralsosupportsyourabilityto
buildstunninggraphics,atopicthatPaulandDaveaddress
inPartIV,CreatingGraphicalOutput.
Letusnotforget,the.NETCompactFrameworkhasnative
supportforconsumingWebServices,theindustrystandard
forintegratingapplicationsacrossanyplatform.Through
thedetailedandextensivesamplesanddiscussionsinthis

book,youwillsoonbeanexpertinbuildingthemost
reliable,effective,data-driven,graphicalapplications;
employingpart-timeandfull-timeconnectivity;andusing
avarietyofdatastoragesolutionsincludingSQLServer
WindowsCEEditionaswellasintegrationwithvirtually
anydatasourceontheserver.
WhetheryouareaseasonedWindowsCEprogrammer,a
developerfamiliarwithusingVisualStudio.NETandthe
.NETFramework,orsomeonetotallynewtobothmobile
developmentand.NETprogramming,thisistheonlybook
youwillneed.Whateveryourbackground,thisbook
providesthetechnicalinsightsandcodingsamplesyou
needtotransferyourexistingskillstothe.NETCompact
Framework.
Thisistrulyanexcitingtimetobepartofthemobile
developmentindustry.Iwouldliketobeamongthefirstto
welcomeandcongratulateyouonjoiningthecommunity
of.NETmobiledevelopers.


Happycoding!
EdKaim
ProductManager
WindowsDeveloperPlatform
MicrosoftCorporation
Amazon


Prev


don'tbeafraidofbuyingbooks

Next


Preface
Wefeelprettyfortunate.Duringthepasttwodecades,we
havetraveledtheworldteachingprogrammerswhatwe
know.Thetwoofushaveledmanyclassesandtogether
havetaughtthousandsofsmart,highlymotivatedsoftware
engineers,testengineers,anddevelopmentmanagers.We
enjoyworkingwiththepeoplewhoareinventingthe
future,andweenjoybeingatthecuttingedgeofeach
successivewaveofsoftwaredevelopmenttechnology.We
havelearnedmuchfromthediscussionswehavehadwith
thesestudents.Thisbookrepresentsonewaywecan
thankthemforalltheirsupport.
Weworkedtogetheronthefirstbookpublishedonthe
subjectofWindowsprogramming,Programmer'sGuideto
Windows(Sybex,1987).Longoutofprint,initsdaythe
bookhelpedmanyprogrammerstacklethechallenges
presentedbyWindowsversion1.01.Thatversionof
WindowscameoutinNovember1985,andinthosedays
developerstypicallyworkedoncomputersrunningMS-DOS
withnoharddrive,nonetworksupport,andnonetwork
serverstorelyon.
Thingshavechangedalotduringthe17yearssinceour
firstbookcameout.Apocket-sizedcomputernowhas
morememoryandCPUpowerthanthetypicaldesktop
systemofthe1980s.Atypicaldesktopsystemhasmore

rawcomputingpowerthanaroomfulofcomputershad
backthen.Withthisincreaseincapacityhascomea
dramaticallyimprovedsetofdevelopmenttoolsavailable
tosoftwaredevelopers:Onlineprogrammingreferences,
context-sensitivehelp,andgraphicaleditorsallhelp
supportthetaskofsoftwaredevelopment.Programmers
canbemoreproductivetodaythankstoallthesetools.


×