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

Addison wesley windows forms 2 0 programming 2nd edition may 2006 ISBN 0321267966

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 (22.26 MB, 1,652 trang )

WindowsForms2.0Programming
ByChrisSells,MichaelWeinhardt
...............................................
Publisher:AddisonWesleyProfessional
PubDate:May16,2006
PrintISBN-10:0-3212-6796-6
PrintISBN-13:978-0-321-26796-2
Pages:1296

TableofContents|Index

"Somebooksaredifferent-thecontentcan'tbeGoogledfromtheInternet,theauthors
havereal-lifeexperiencestoshare,thecodecanbeusedinreal-worldprojects.Thisisone
ofthosebooks."
NealMyrddin,IndependentDeveloper

"ChrisandMichaelnailthesoulofWindowsForms2.0.Thisbookprovidesaninsightful
viewintothedesignofWindowsFormsandtheintegrationofnew2.0features.Itisjust
asapplicableforthefirst-timeWindowsFormsprogrammerastheseasonedlineof
businessdeveloper.The'What'sNewin2.0'appendixisworththepriceofadmission
alone."
MikeHarsh,WindowsFormsProgramManager,Microsoft,Inc.

"Thisbooktakesanamazinglybroadanddeeptechnology,andbreaksitintomanageable
piecesthatareeasilyconsumed.YoucannotsurvivebuildingacomplexWinForms
applicationwithoutthisbook."
RyanDorrell,ChiefTechnologyOfficer,AgileThought

"WindowsForms2.0Programmingofferssomethingforevery.NETdeveloper.Experienced
developerswillappreciatethein-depthcoverageofnew2.0features,includingthemost
comprehensivecoverageofClickOncedeployment,multithreading,andthenewdesigner


integrationfoundanywhere.DevelopersnewtoWinformsprogrammingwillappreciatethe
coverageofthefundamentalsallWinformsdevelopersneedtoknow.Whetheryou'rean
experiencedWinFormsdeveloperorjustbeginning,youneedthisbook."
FritzOnion,cofounderofPluralsight,authorofEssentialASP.NET,andASP.NETMVP



"Idon'twantjustadescriptionoftheWinFormswidgets.Icangetthatonlineorfrom
otherbooks.WhatIwantisaroadmapforpitfallstoavoid,andinnovativesolutionsfor
commonproblems.Thatiswherethisbookshines.Allofuswhofoundthefirsteditionof
thisbooktobeanindispensiblepartofourreferencelibrarywillappreciatethisupdated
editionthatdescribesWinForms2.0."
JohanEricsson,SoftwareEngineer,AgilentTechnologies

"ThebooksChrisSellswritesarealwaysinsightfulandthisnewestadditionisnodifferent.
Thisbookinparticularisforthosewhowanttounderstandnotjusttheflashysurfaceof
WindowsForms2.0,butalsohowitfitsintothe.NETenvironment.Readerswillhavethis
bookattheirdesks,notstuckontheirshelves,forquitealongtime."
YoshimatsuFumiaki,SoftwareEngineerbasedinTokyoJapan

"ChrisandMikehavedoneanexcellentjobpresentingtheinformationyouneedtobe
successfulwithWindowsForms."
JessicaFosler,DevTechLead,Microsoft

"Thisbookisthe'musthave'teachingandreferencebookforWinForms2.0."
JimRittenhouse,SeniorSoftwareEngineer,Siemens

WindowsForms2.0ProgrammingisthesuccessortothehighlypraisedWindows
FormsProgramminginC#.Thiseditionhasbeensignificantlyupdatedtoamalgamatethe
sheermassofnewandimprovedsupportthatisencompassedbyWindowsForms2.0,the

.NETFramework2.0,andVisualStudio2005.Thisistheonebookdevelopersneedin
ordertolearnhowtobuildanddeployleading-edgeWindowsForms2.0applications.

ReaderswillgainadeepunderstandingfromSellsandWeinhardt'spractical,well-balanced
approachtothesubjectandclearcodesamples.

•WindowsForms2.0fundamentals,includingforms,dialogs,datavalidation,help,
controls,components,andrendering
•Staticanddynamiclayout,snaplines,HTML-styleflowandtablelayout,automatic
resizing,andautomaticcross-DPIscaling
•Office2003-styletoolstripcontrolcoverage,includingdynamiclayoutandcustom
rendering
•Design-timeintegrationwiththeVisualStudio2005PropertiesWindowandSmart
Tags


•Resourcemanagement,stronglytypedresources,andinternationalization
considerations
•Stronglytypedapplicationandusersettings
•SDI,MDI,SingleInstancing,Multiple-InstanceSDI,Single-InstanceMDI,databasecentric,anddocument-centricapplications
•Databindingdata-sourcemanagement,drag-and-dropdatabinding,theBindingSource,
theBindingNavigator,andapplieddatabinding
•Events,delegates,multithreadedUIs,long-runningoperations,simplified
multithreadingwiththeBackgroundWorker,andasynchronouswebservicecalls
•ClickOnceapplicationdevelopmentpublishing,shellintegration,andpartialtrust
security
•BestpracticesfordeveloperstransitioningfromWindowsForms1.0andMFC




WindowsForms2.0Programming
ByChrisSells,MichaelWeinhardt
...............................................
Publisher:AddisonWesleyProfessional
PubDate:May16,2006
PrintISBN-10:0-3212-6796-6
PrintISBN-13:978-0-321-26796-2
Pages:1296

TableofContents|Index













































Copyright
Microsoft.NETDevelopmentSeries
AbouttheAuthors
Foreword
Preface
Chapter1.Hello,WindowsForms

WindowsFormsfromScratch
WindowsFormsinVisualStudio.NET
ArrangingControls
Controls
ApplicationSettings
Resources
Dialogs
Drawing
Printing
DataBinding
MultithreadedUserInterfaces
Deployment
WhereAreWe?
Chapter2.Forms
ShowingForms
FormLifetime
FormNotification
FormSizeandLocation
















































































FormAdornments
FormTransparency
FormandContextMenus
ToolStrips
StatusStrips
MultipleDocumentInterfaceApplications
VisualInheritance
WhereAreWe?
Chapter3.Dialogs
StandardDialogs
FormStyles
DataExchange
DataValidation
ImplementingHelp
WhereAreWe?
Chapter4.Layout
FixedLayout
DynamicLayout
LayoutControls
LayoutOptimization
CustomLayout
WhereAreWe?
Chapter5.DrawingBasics
DrawingtotheScreen
Colors

Brushes
Pens
Shapes
Paths
Images
WhereAreWe?
Chapter6.DrawingText
Fonts
Strings
TheTextRenderer
ATaleofTwoTechnologies
WhereAreWe?
Chapter7.AdvancedDrawing
PageUnits

















































































Transforms
Regions
OptimizedDrawing
WhereAreWe?
Chapter8.Printing
PrintDocuments
PrintControllers
BasicPrintEvents
Margins
PageSettings
PrinterSettings
UsefulPrintingTechniques
WhereAreWe?
Chapter9.Components
ComponentsDefined
UsingComponents
CreatingCustomComponents
WhereAreWe?
Chapter10.Controls
ControlsDefined
UsingControls
ThemedControls
Owner-DrawnControls
ExtendingExistingControls
CustomControls
UserControls
HostingCOMControls
WhereAreWe?

Chapter11.Design-TimeIntegration:ThePropertiesWindow
Design-TimeComponents
Hosts,Containers,andSites
DebuggingDesign-TimeFunctionality
TheDesignModeProperty
Attributes
CodeSerialization
BatchInitialization
ExtenderPropertyProviders
TypeConverters
UITypeEditors














































































WhereAreWe?
Chapter12.Design-TimeIntegration:DesignersandSmartTags
Designers

SmartTags
WhereAreWe?
Chapter13.Resources
ResourceBasics
StronglyTypedResources
ApplicationInternationalization
WhereAreWe?
Chapter14.Applications
Applications
Single-InstanceApplications
WhereAreWe?
Chapter15.Settings
TheApplicationEnvironment
Application,User,andRoaming-UserSettings
StronglyTypedSettings
UsingStronglyTypedSettings
DesignerSettings
AlternativeStorageforSettings
WhereAreWe?
Chapter16.DataBindingBasics
TheLandbeforeDataBinding
SimpleDataBindingandItemDataSources
SimpleBindingandListDataSources
ComplexBindingandListDataSources
IBindingList
BindingList<T>
TheBindingSourceComponent
Design-TimeDataSources
BindingUIElementsintheDesigner
WhereAreWe?

Chapter17.AppliedDataBinding
Drag-and-DropDataBinding
FundamentalsofData-BoundUIs
DataViews
Real-WorldData-BoundUIs
WhereAreWe?











































Chapter18.MultithreadedUserInterfaces

































Long-RunningOperations
AsynchronousWebServices
WhereAreWe?
Chapter19.ClickOnceDeployment
ADayintheLifeofClickOnceDeployment
ClickOnceConfiguration
ClickOnceSecurity
ManagingPermissions
ConsiderationsforPartiallyTrustedAssemblies

ProcessingCommandLineArguments
WhereAreWe?
AppendixA.What'sNewinWindowsForms2.0
AFewWordsAboutWindowsForms
WindowsForms2.0Enhancements
WindowsForms2.0:TheImprovements
AppendixB.MovingfromMFC
AFewWordsAboutMFC
MFCVersusWindowsForms
MFCandWindowsFormsInterop
WindowsFormsasaBetterMFC
AppendixC.DelegatesandEvents
Delegates
Events
AnonymousDelegates
HappinessintheUniverse
AppendixD.ComponentandControlSurvey
Components
Controls
AppendixE.DragandDrop
EnablingDragandDrop
AddingSupportforMultipleDrag-and-DropEffects
CustomizingDragandDrop
DragandDropofMultipleDataItems
FileDragandDrop
AppendixF.DocumentManagement
TheFileDocumentComponent
ShellIntegration
TheMruMenuManagerComponent





OpeningFilesDraggedandDroppedfromtheShell


Bibliography




ColorInsert

Index


Copyright
Manyofthedesignationsusedbymanufacturersandsellersto
distinguishtheirproductsareclaimedastrademarks.Where
thosedesignationsappearinthisbook,andthepublisherwas
awareofatrademarkclaim,thedesignationshavebeenprinted
withinitialcapitallettersorinallcapitals.
The.NETlogoiseitheraregisteredtrademarkortrademarkof
MicrosoftCorporationintheUnitedStatesand/orother
countriesandisusedunderlicensefromMicrosoft.The
followingarticleswereoriginallyprintedinMSDNMagazine,and
arereprintedinthisbookwithpermission.".NETZero
Deployment:SecurityandVersioningModelsintheWindows
FormsEngineHelpYouCreateandDeploySmartClients"by
ChrisSells,MSDNMagazine,July2002."VisualStudio.NET:

BuildingWindowsFormsControlsandComponentswithRich
Design-TimeFeatures"byMichaelWeinhardtandChrisSells,
MSDNMagazine,April2003."VisualStudio.NET:Building
WindowsFormsControlsandComponentswithRichDesignTimeFeatures,Part2"byMichaelWeinhardtandChrisSells,
MSDNMagazine,May2003.".NETFramework2.0:CraftaRich
UIforYour.NETAppwithEnhancedWindowsFormsSupport"
byMichaelWeinhardtandChrisSells,MSDNMagazine,May
2004."SmartTags:SimplifyUIDevelopmentwithCustom
DesignerActionsinVisualStudio"byMichaelWeinhardt,MSDN
Magazine,July2005."DraftaRichUI:GroundRulesfor
BuildingEnhancedWindowsFormsSupportintoYour.NETApp"
byMichaelWeinhardtandChrisSells,MSDNMagazine,May
2005.
Theauthorsandpublisherhavetakencareinthepreparationof
thisbook,butmakenoexpressedorimpliedwarrantyofany
kindandassumenoresponsibilityforerrorsoromissions.No
liabilityisassumedforincidentalorconsequentialdamagesin


connectionwithorarisingoutoftheuseoftheinformationor
programscontainedherein.
Thepublisheroffersexcellentdiscountsonthisbookwhen
orderedinquantityforbulkpurchasesorspecialsales,which
mayincludeelectronicversionsand/orcustomcoversand
contentparticulartoyourbusiness,traininggoals,marketing
focus,andbrandinginterests.Formoreinformation,please
contact:
U.S.CorporateandGovernmentSales
(800)382-3419


ForsalesoutsidetheUnitedStatespleasecontact:
InternationalSales

LibraryofCongressCataloging-in-PublicationData:
Sells,Chris.
WindowsForms2.0programming/ChrisSells&
MichaelWeinhardt.
p.cm.
ISBN0-321-26796-6(pbk.:alk.paper)
1.Microsoft.NETFramework.2.Computer
softwareDevelopment.I.Weinhardt,
Michael.II.Title.
QA76.76.M52S442006
005.2'768dc22
2006000194
Copyright©2006ChrisSellsandMichaelWeinhardtAllrights
reserved.PrintedintheUnitedStatesofAmerica.This
publicationisprotectedbycopyright,andpermissionmustbe
obtainedfromthepublisherpriortoanyprohibited
reproduction,storageinaretrievalsystem,ortransmissionin


anyformorbyanymeans,electronic,mechanical,
photocopying,recording,orlikewise.Forinformationregarding
permissions,writeto:
PearsonEducation,Inc.
RightsandContractsDepartment
75ArlingtonStreet,Suite300
Boston,MA02116
Fax:(617)848-7047

TextprintedintheUnitedStatesonrecycledpaperatEdwards
BrothersinAnnArbor,MichiganFirstprinting,May2006
"Somebooksaredifferentthecontentcan'tbeGoogled
fromtheInternet,theauthorshavereal-lifeexperiences
toshare,thecodecanbeusedinreal-worldprojects.This
isoneofthosebooks.Andit'snotasimpleupgradeofthe
1stedition;thisbookhasbeencompletelyrefittedto
presentWinForms2.0asitshouldbepresented."
NealMyrddin,IndependentDeveloper
"ChrisandMichaelnailthesoulofWindowsForms2.0.
Thisbookprovidesaninsightfulviewintothedesignof
WindowsFormsandtheintegrationofnew2.0features.It
isjustasapplicableforthefirst-timeWindowsForms
programmerastheseasonedlineofbusinessdeveloper.
TheWhat'sNewin2.0appendixisworththepriceof
admissionalone."
MikeHarsh,WindowsFormsProgramManager,Microsoft,
Inc.
"Thisbooktakesanamazinglybroadanddeep
technology,andbreaksitintomanageablepiecesthatare
easilyconsumed.Youcannotsurvivebuildingacomplex
WinFormsapplicationwithoutthisbook."


RyanDorrell,ChiefTechnologyOfficer,AgileThought
"WindowsForms2.0Programmingofferssomethingfor
every.NETdeveloper.Experienceddeveloperswill
appreciatethein-depthcoverageofnew2.0features,
includingthemostcomprehensivecoverageofClickOnce
deployment,multithreading,andthenewdesigner

integrationfoundanywhere.DevelopersnewtoWinforms
programmingwillappreciatethecoverageofthe
fundamentalsallWinformsdevelopersneedtoknow.
Whetheryou'reanexperiencedWinFormsdeveloperor
justbeginning,youneedthisbook."
FritzOnion,cofounderofPluralsight,authorofEssential
ASP.NET,andASP.NETMVP
"Idon'twantjustadescriptionoftheWinFormswidgets.I
cangetthatonlineorfromotherbooks.WhatIwantisa
roadmapforpitfallstoavoid,andinnovativesolutionsfor
commonproblems.Thatiswherethisbookshines.Allof
uswhofoundthefirsteditionofthisbooktobean
indispensiblepartofourreferencelibrarywillappreciate
thisupdatededitionthatdescribesWinForms2.0."
JohanEricsson,SoftwareEngineer,AgilentTechnologies
"ThebooksChrisSellswritesarealwaysinsightfulandthis
newestadditionisnodifferent.Thisbookinparticularis
forthosewhowanttounderstandnotjusttheflashy
surfaceofWindowsForms2.0,butalsohowitfitsintothe
.NETenvironment.Readerswillhavethisbookattheir
desks,notstuckontheirshelves,forquitealongtime."
YoshimatsuFumiaki,SoftwareEngineerbasedinTokyo
Japan
"ChrisandMikehavedoneanexcellentjobpresentingthe


informationyouneedtobesuccessfulwithWindows
Forms."
JessicaFosler,DevTechLead,Microsoft
"Thisbookisthe'musthave'teachingandreferencebook

forWinForms2.0."
JimRittenhouse,SeniorSoftwareEngineer,Siemens

Dedication
Tomywife,Melissa,andmysonsJohnandTom.They
definetheheaventhatexceedsmygrasp.Andtomy
parents,whomademeareaderfromthebeginningand
whopassedonthesecretwritergene,muchtomy
surprise.
ChrisSells
ToJosefandLili,forallthatIamandallthatI'vedone.
ToAlex,forallthatIwouldliketobeandwishIcoulddo.
MichaelWeinhardt


Microsoft.NETDevelopmentSeries
JohnMontgomery,SeriesAdvisor
DonBox,SeriesAdvisor
MartinHeller,SeriesEditor
TheMicrosoft.NETDevelopmentSeriesissupportedand
developedbytheleadersandexpertsofMicrosoftdevelopment
technologiesincludingMicrosoftarchitectsandDevelopMentor
instructors.Thebooksinthisseriesprovideacoreresourceof
informationandunderstandingeverydeveloperneedsinorder
towriteeffectiveapplicationsandmanagedcode.Learnfrom
theleadershowtomaximizeyouruseofthe.NETFramework
anditsprogramminglanguages.


TitlesintheSeries

BradAbrams,.NETFrameworkStandardLibraryAnnotated
ReferenceVolume1:BaseClassLibraryandExtendedNumerics
Library,0-321-15489-4
BradAbramsandTamaraAbrams,.NETFrameworkStandard
LibraryAnnotatedReference,Volume2:NetworkingLibrary,
ReflectionLibrary,andXMLLibrary,0-321-19445-4
KeithBallinger,.NETWebServices:Architectureand
Implementation,0-321-11359-4
BobBeauchemin,NielsBerglund,DanSullivan,AFirstLookat
SQLServer2005forDevelopers,0-321-18059-3
DonBoxwithChrisSells,Essential.NET,Volume1:The
CommonLanguageRuntime,0-201-73411-7
KeithBrown,The.NETDeveloper'sGuidetoWindowsSecurity,
0-321-22835-9
EricCarterandEricLippert,VisualStudioToolsforOffice:Using
C#withExcel,Word,Outlook,andInfoPath,0-321-33488-4
EricCarterandEricLippert,VisualStudioToolsforOffice:Using
VisualBasic2005withExcel,Word,Outlook,andInfoPath,0321-41175-7
MaheshChand,GraphicsProgrammingwithGDI+,0-32116077-0
KrzysztofCwalinaandBradAbrams,FrameworkDesign
Guidelines:Conventions,Idioms,andPatternsforReusable
.NETLibraries,0-321-24675-6
AndersHejlsberg,ScottWiltamuth,PeterGolde,TheC#


ProgrammingLanguage,0-321-15491-6
AlexHomer,DaveSussman,MarkFussell,ADO.NETand
System.Xmlv.2.0TheBetaVersion,0-321-24712-4
AlexHomer,DaveSussman,RobHoward,ASP.NETv.2.0The
BetaVersion,0-321-25727-8

JamesS.MillerandSusannRagsdale,TheCommonLanguage
InfrastructureAnnotatedStandard,0-321-15493-2
ChristianNagel,EnterpriseServiceswiththe.NETFramework:
DevelopingDistributedBusinessSolutionswith.NETEnterprise
Services,0-321-24673-X
BrianNoyes,DataBindingwithWindowsForms2.0:
ProgrammingSmartClientDataApplicationswith.NET,0-32126892-X
FritzOnion,EssentialASP.NETwithExamplesinC#,0-20176040-1
FritzOnion,EssentialASP.NETwithExamplesinVisualBasic
.NET,0-201-76039-8
TedPattisonandDr.JoeHummel,BuildingApplicationsand
ComponentswithVisualBasic.NET,0-201-73495-8
Dr.NeilRoodyn,eXtreme.NET:IntroducingeXtreme
ProgrammingTechniquesto.NETDevelopers,0-321-30363-6
ChrisSells,WindowsFormsProgramminginC#,0-321-116208
ChrisSellsandJustinGehtland,WindowsFormsProgramming
inVisualBasic.NET,0-321-12519-3
PaulVick,TheVisualBasic.NETProgrammingLanguage,0321-16951-4


DamienWatkins,MarkHammond,BradAbrams,Programming
inthe.NETEnvironment,0-201-77018-0
ShawnWildermuth,PragmaticADO.NET:DataAccessforthe
InternetWorld,0-201-74568-2
PaulYaoandDavidDurant,.NETCompactFramework
ProgrammingwithC#,0-321-17403-8
PaulYaoandDavidDurant,.NETCompactFramework
ProgrammingwithVisualBasic.NET,0-321-17404-6
Formoreinformationgoto
www.awprofessional.com/msdotnetseries/





AbouttheAuthors
ChrisSellsisaprogrammanagerfortheConnectedSystems
Division.He'swrittenseveralbooks,includingProgramming
WindowsPresentationFoundation(O'Reilly),WindowsForms
ProgramminginC#(Addison-Wesley),andATLInternals
(Addison-Wesley).Inhisfreetime,Chrishostsvarious
conferencesandmakesapestofhimselfonMicrosoftinternal
productteamdiscussionlists.MoreinformationaboutChrisand
hisvariousprojectsisavailableat.
MichaelWeinhardtisaprogrammer/writeratMicrosoft,
workingontheWindowsClientSDK.Michaelhascoauthoreda
varietyofarticleswithChris,contributedtothe"Wondersof
WindowsForms"columnatMSDNOnline,reviewedseveral
Windowstechnologybooks,andgenerallylovescommunicating
thewhysandwhereforesoftechnologytohispeers.Michaelis
surethathisparentsattributehisfascinationintechnologyto
theirpurchaseofanAmiga1000inthemid-80s.Theywouldbe
right.


Foreword
Along,longtimeagowhenIbeganprogrammingPCGUIs,
therewerenoneofthesefancyframeworkthingies.Onewrote
awholelotofCcodeinacasestatementlongenoughtocuta
giant'sundershirtoutof.I'dspentacoupleweeks
understandingandimplementingDDE(yes,DDE)inthe

applicationwewerebuilding(andfrankly,itwasnotthemost
pleasantexperience)whenIranacrossanarticleinamagazine
showinghowthisfancythingcalled"Smalltalk"coulddoDDEin
acoupleoflinesofcode.Wow!Ithought.That'sthewayIwant
toprogram!I'vebeenworkingwithandonUIframeworks
prettymucheversince,whichishowIendedupworkingon
WindowsFormsatMicrosoft.
ForV1ofWindowsForms,ourgoalwastoproducea
comprehensiveUIframeworkthatcombinedtheeaseofuseof
VBwiththeextensibilityandflexibilityofMFC.Alongtheway,
wepickedupadditionalgoals,includingrichdesign-time
extensibility,GDI+support,andsupportforpartialtrustforNo
TouchDeployment(NTD).Ithinkwedidareasonablejobof
meetingthesegoals.Despitethefocusonthe"webstuff"when
wefirstreleased,thereareanenormousnumberofpeople
usingWindowsFormstodaytobuildalltypesofapplications,
fromphotomanagementsoftwaretoapplicationssupporting
corebusinessprocesses.Ifindseeingtheinteresting
applicationspeoplebuildwithWindowsFormsoneofthemore
rewardingpartsofmyjob.However,tobehonest,thereare
areaswherewecouldhavedonebetterforexample,NTDhad
noVisualStudiosupportandcouldbecomplextodebugwhen
thingswentwrongsooverall,IhavetogiveV1ofWindows
Formsa"showspromise"rating.
V2ofWindowsFormsisaboutdeliveringonthatpromise.This
isamajorupgradetoWindowsForms.Almosteveryareaof


WindowsFormsdesign-timeandrun-timehasbeenimproved.As
ChrisandMichaelcalloutinAppendixA:What'sNewin

WindowsForms2.0,wehaveincorporatedcompletelynew
featuresandalargenumberofimprovementstoourexisting
features(apparentlywehave329newtypes,139updated
types,and14,323newmembers).RatherthanrepeatAppendix
A,I'mgoingtocalloutthreenewfeaturesthatIthinkillustrate
howweachievedourgoalsforthisversionofWindowsForms:
solvedeployment,enablegreat-lookingapps,andenhance
productivity.

Deployment
IthinkthesinglemostsignificantfeatureinV2ofthe.NET
Framework(notjustWindowsForms,butthewhole.NET
Framework)isClickOnce.ClickOncedeliversonthepromiseof
NoTouchDeploymenttobringeasy,reliable,andmanageable
web-baseddeploymenttoclientapplications.Deployingyour
applicationviathewebisnowsimplyamatterofstepping
throughawizardinVisualStudio2005.

Great-LookingApps
EversinceIjoinedMicrosoft,customershaveaskedforthe
abilitytobuildapplicationsthatlooklikeMicrosoftOffice"outof
thebox,"andyoucandoexactlythatwithV2ofWindows
Formsusingthenewmenustrip,toolstrip,andstatusstrip
controlsToolStrip,MenuStrip,andStatusStrip.Notonlydothe
stripcontrolssupportthestandardWindowsandOfficelookand
feel,buttheycanalsobecustomizedtolooklikeprettymuch
anythingyoufancy.

Productivity
We'veaddedawholesetofdesign-timeandrun-time



improvementsthatwebelievewillhelpyoutobemore
productive.Oneofmyfavoritenewdesignerfeaturesis
SnapLines,whichallowsyoutoquicklyaligncontrolswitheach
otherasyoulayoutyourforms.Onceyou'veusedadesigner
withSnapLines,youneverwanttogobackit'sthedesigner
equivalentofIntelliSense.

TheFuture
AftershippingV2,ourthoughtsarenaturallyturningtothe
future.Predictingthefutureisadangerousbusinessmostofthe
predictionsfromwhenIwasakidmeanweshouldbe
supportingactorsineitherTheJetsonsor1984bynowandso
I'malittlenervousaboutmakinganylong-termpredictions.
However,Icansayafewthingsbasedonwhereweareand
whatIwouldliketoseeusdo.First,the.NETFrameworkand
managedcodeisheretostay:Itistheprogrammingmodelof
thepresentandthefuture.Learningtousethe.NETFramework
andWindowsFormsisasolidinvestmentforthefuture.
Second,toparaphraseSamuelClemensterribly,"Reportsofthe
deathofclientappsaregreatlyexaggerated."Client
applicationsareheretostay,cannowbedeployedaseasilyas
webapplications,providesignificantbusinessvalue,andwill
providemorevalueastimeprogresses.Third,aspartofour
continuedinvestmentinWindowsForms,wewillensurethat
WindowsFormsworkswellwithnewtechnologiescomingdown
thepipesuchasthoseinWinFX.Thisallowsyoutobuild
applicationstodaywiththeknowledgethatyouwillbeableto
enhancethoseapplicationsinthefutureusingbothWindows

Formsandthesenewtechnologiesastheybecomeavailable.
Finally,fromaWindowsFormsperspective,Ibelieveweneedto
broadenwhatweprovideintoaframeworkanddesign
experiencethataddressestheend-to-endprocessofbuildinga
clientapplication.Wehaveagreatdesignertohelpyoubuild
yourUI,butyoustillhavetowritewaytoomuchcodetobuild
yourwholeapplication.Iwouldliketoseeusprovideagreat


designer-basedexperienceforyourentireapplication,notjust
yourforms.
SohopefullywhatI'vesaidaboutWindowsFormshasgotyou
atleastalittlecurioustofindoutmorewhichiswherethisbook
comesin.Thefirsteditionofthisbookwasagreatoverviewof
andintroductiontoWindowsForms.Thesameistrueofthis
secondedition.WhetheryouarelearningWindowsFormsfor
thefirsttimeorifyoujustwanttogetahandleonthenew
stuffwe'vedoneinV2,thisbookwillhelpyou.Itcoversallof
thesignificantfeatureareas,fromthebasicsofcreatingForms,
throughToolStripsanddatabindingtodeploymentwith
ClickOnce.
Thebookisagreatbalancingact:ItneitherignoresVisual
Studio2005norreducesitselftoasimplistic"Clickherethen
clickhere"walkthroughofVisualStudio2005features.The
booknotonlyexplainstheconceptsandshowsyouhowtouse
thoseconceptsincode,butitalsoshowsyouhowthedesigner
helpsyoutobemoreproductivebyautomaticallygenerating
thecodeforyou.Thisleavesyouwithasolidunderstandingof
bothhowthingsworkandhowtouseVisualStudio2005toget
thingsdoneasproductivelyaspossible.Thechaptersondata

binding(16and17)areagreatexampleofthisapproach.The
sourcecodeexamplesareanothergreatbalancingact:They
areneithertooshorttobeusefulnorsolongastobe
overwhelming.ToquoteAlanCooper,theyare"Goldilockscode"
examplesbecausetheyare"justright."
Iwouldliketoparticularlyhighlightthechaptersondata
binding(Chapters16and17),notjustbecausedatabindingis
veryclosetomyheart,butbecausethebookdoesanexcellent
jobofexplaininghowdatabindingworksandhowtouseit
effectively.Iwouldalsoliketohighlightthechaptersonwriting
design-timebehaviorforyourcontrolsandcomponents
(Chapters11and12)becausethisisasubjectthatisoften
neglected.Thesechaptersalonemakethisa"mustread"book.


So,insummary,thisbookwillleaveyounotonlyinaposition
toeffectivelyusewhatweprovideaspartofWindowsForms
butalsowiththeunderstandingyouneedtowriteyourown
run-timeanddesign-timeextensionstowhatweprovide.
I'dliketoclosewithsomeacknowledgmentsandthanks.First,
thankstotheentireWindowsFormsteam,whohaveworked
tirelesslytobuildandshipwhatIbelieveisagreatproduct.I'm
veryproudofwhatwehaveachieved.Second,mythanksto
MichaelandChrisnotonlyforproducingabookthatdoesa
greatjobofexplainingourproductandwillmakeiteasierfor
ourcustomerstouse,butalsofortheircontributionstothe
widerWindowsFormscommunity.ThankstoMichaelforhis
greatarticlesonMSDNandfeedbackonWindowsForms
V2particularlyhisfeedbackontheToolStripcontrols.Thanksto
ChrisforhisseeminglyboundlessenthusiasmforWindows

Forms,hisexcellentwritingonWindowsForms,hisdeep
understandingofWindowsForms,MFC,andWindows,andhis
politeandmeasuredbutenthusiasticandcopiousfeedbackon
everyaspectoftheproduct.BothMikeandChrishavehelped
enormouslybothinpromotingunderstandingoftheproductand
inhelpingmakeWindowsFormsasgoodasitistoday.And
finally,mythankstoourcustomers:Everysinglefeaturein
WindowsFormsV2isbasedonyourfeedback.Sotoallofyou
whotookthetimetogiveusfeedbackandsuggestions:
Thanks!Pleasekeepitcoming!
IhopeyouhavefunusingWindowsForms.
MarkBoulter
PMTechnicalLead,
ClientDevelopmentTools,Microsoft


Preface
Windows1.0programmershadastraightforwardlife.Theyhad
almostnochoicesabouthowtodothings;eithertherewasan
applicationprogramminginterface(API),ortherewasn't,and
mostofthetimetherewasn't.Thismeantthatdevelopershad
tobuildalmosteverythingbyhand.Atthetime,thiswasn'ta
problem.AllWindowsprogrammershadthesamelimitations,
soeveryone'sappsmoreorlessoperatedwiththesamelimited
setoffunctionality.
AmodernWindowsdeveloper,ontheotherhand,isinundated
withchoices.Theinventionofthewebalonegivesusstatic
HypertextMarkupLanguage(HTML),server-baseduser
interface(UI)interactionviaASP.NET,andclient-sideUI
interactionviaActiveXcontrolsorAJAX(tonameafew).[1]On

theclientside,wehavenativeframeworkslikeMicrosoft
FoundationClasses(MFC),ActiveTemplateLibrary(ATL),and
thenext-generationmanagedframeworkknownasthe
WindowsPresentationFoundation(WPFispartofWinFX,the
follow-ontothe.NETFramework).Howdoesadeveloper
choose?WheredoesWindowsForms2.0,thetopicofthisbook,
fitintothispantheon?
[1]AJAXstandsforAsynchronousJavaScriptandXML,asdefinedbyJesseJamesGarrett,"Ajax:ANew
ApproachtoWebApplications," />( />
ClienttechnologiesonWindowsprovidearangeofreachand
richnessininverseproportiontoeachother.Reachistheability
ofauserinterface(UI)toworkacrossoperatingsystems,
whereasrichnessistheabilityforaUItotakeadvantageofthe
operatingsystemonwhichitruns.SoeventhoughstaticHTML
worksalmosteverywhere,totheextentthatyourHTMLuses
client-sideJScript,reachisdiminishedforbrowsersthatdon't
supportthescriptingconstructsbeingused.Evenfurtherdown


×