Tải bản đầy đủ - 0 (trang)
Appendix A. Visual Studio .NET IDE

Appendix A. Visual Studio .NET IDE

Tải bản đầy đủ - 0trang

SourceEditing

ThemostimportantwindowyouwillworkwithintheIDEisthe

sourcecodewindow.Forsakeofclarity,thesourcewindowalso

displaysdifferentdesignersbasedonthefileformatofthefile

beingedited,butthisdiscussionfocusesonthesourcecode

windowasitrelatestoC#sourcecodefiles.



CodeOutlining

Outliningisafeaturethatplaceslogicalcodeblocksinto

collapsiblesectionssimilartothatofatreecontrol.Bydefault,

thesourcecodefornewprojectsisdisplayedinitsexpanded

state,exceptforcodethatisofflimitssuchasWindowsForm

designer-generatedcode.Byright-clickingwithinthesource

codewindoworselectingtheEdit,Outliningpop-upmenufrom

themainmenu,youcanviewalistofoutliningcommands.The

ToggleOutliningExpansioncollapsesasectiontoasingleline

andplacesanellipsisattheendofthatlineorexpandsthe

sectionifitisalreadycollapsed.Thisactionissimilartoclicking

thetreenodecontrolalongtheleftsideofthesourcewindow.

TheToggleAllOutliningcommandcollapsesallcodeblocksor

expandsthemiftheyarealreadycollapsed.Finally,theCollapse

toDefinitionsitemparsesthesourcecodefileandcollapsesthe

codesothatonlymethoddeclarationsarevisible.Forthose

whoarefamiliarwithC++,thisviewissimilartothatofa

headerfile.Youcanalsodisableoutliningatanytimeby

selectingtheStopOutliningmenuitem.

OutliningusesC#languageconstructstodetermineregionsto

create.Inotherwords,regionsarecreatedformatchingbraces,

includingthosedenotingaconditionalcontrolblocksuchasan

ifstatementordo/whileblock.Youcanalsodefineyourown



regionsbyusingthe#regionand#endregionpreprocessor

directives.Thefollowingexampledemonstrateshowtocreatea

regionthatcanbecollapsedformembervariableswithina

class:



namespace_MyProject

{

publicclassForm1:System.Windows.Forms.Form

{

#regionWindowsFormControlVariables

privateSystem.Windows.Forms.DataGriddataGrid1;

privateSystem.Windows.Forms.MenuItemmenuItem1;

privateSystem.Windows.Forms.MenuItemmnuExit;

#endregion

}

}



IntelliSense

IntelliSenseisthetechnologyusedbytheIDEthatdisplayshelp



informationwithinatooltiporaselectablelistboxasyoutype

insourcecode.Forinstance,enteringavariablenamethat

representsaclassandfollowingitwiththedotoperatorfor

memberaccessdisplaysalistboxthatallowsyoutochoosethe

properclassmethodorvariable.Asyoucontinuetyping,thelist

boxchangestoreflecttheclosestmatchbasedonthecurrent

typedcharacters.Atanytimethelistboxhighlightsthe

memberyouarelookingfor,presstheTabkeytocompletethe

word.Youcanadditionallyusetheup-anddown-arrowkeysor

PageUpandPageDownkeystonavigatetothecorrectmember.

Asyouenteraparenthesisdenotingamethodcall,aspecialized

tooltipappearslistingthepossiblemethodparameters.Ifany

otheroverloadedversionsofthemethodexist,youseean

up/downcontrolontheleftsideofthetooltip.Youcanusethe

up-anddown-arrowkeystoselecttheproperoverloaded

versionthatyouwanttouse,andasyouentereachparameter,

thetooltipmarksyourlocationusingaboldtypeface.

IntelliSensealsoallowsyoutoviewinformationaboutadata

typeormethodparametersatanytimeusingtheIntelliSense

toolbarbuttonsormenuitemaccessedthroughtheEditmenu.

Clickingawayforthecurrenteditingpositionwhileediting

sourcecoderemovesanytooltiporlistboxthatisdisplayed.If

youplaceyourcursorbacktothatpositionandaccessoneof

theIntelliSensemenuortoolbaritems,thetooltiporlistbox

reappears.



Bookmarks

Bookmarksallowyoutomarkpositionswithinyourcodethat

youwanttofrequentlyaccesswhileworkinginyourproject.

Thebookmarkcommandsappearonthetoolbar,easily

recognizablebyagroupofblueflags,orontheEditmain

menu.Ifyoupositionyourcursorataparticularlineinthe

sourcewindowandselecttheToggleBookmarkcommand,a



cyancoloredmarkerappearsintheleft-sidemarginofthe

sourcecodewindow.Ifyouplaceanadditionalbookmarkwithin

thesamefile,youcanswitchbetweenthelocationsbyusing

thenextandpreviousbookmarkcommands.Theyonlynavigate

tobookmarkswithinthesamesourcefile,whichmeansyouare

unabletotogglebetweentwobookmarksiftheyareindifferent

sourcefiles.



CreatingTaskListShortcuts

TheTaskListwindowisgenerallyusedtodisplaywarningsand

errorsthatarisewheneveryoucompileyourproject.Clickingon

thewarningorerrortakesyoutothecorrespondinglineinthe

sourcecode,allowingyoutofixit.Youcanalsousethesource

codewindowtocreateautomaticentrieswithinthetasklistto

createshortcuts.Tocreateatasklistshortcut,placethecursor

onthelinetocreatetheshortcuttoandclickontheAddTask

ListShortcutmenuitemaccessedthroughtheEdit,Bookmarks

menu.Toviewthelistofshortcutswithinthetasklist,rightclickontheTaskListwindowandselectShowTasks,Shortcuts.

Youcanalsoautomaticallycreatetasklistshortcutsbycreating

specializedcomments.Toautomaticallyplaceashortcutinto

thetasklist,addthesingle-linecommentoperator(//);

followedbyatasklistkeywordsuchasTODO,HACK,orUNDONE;

followedbythetexttodisplayinthetasklist.Youcan

optionallycreateyourownkeywordsbyclickingonTools,

Optionsfromthemainmenu;selectingtheEnvironment,Task

Listpropertypage;andfillingintheNamefieldwithanew

keyword.Youcansettheprioritytolow,medium,orhigh.



ToolWindows

Toolwindowsaretheoutlyingwindowssurroundingthesource

codeviewwhichcontainspecializedfunctionsandviewsthat

complementtheitemcurrentlybeingedited.



CommonToolWindows

ThefollowingisalistofthedefaulttoolwindowswithintheIDE

andthefunctionsthattheyperform:

SolutionExplorerThiswindowdisplaysthehierarchical

organizationofthefileswithinyourproject.Thelayoutof

thefilesdirectlymirrorsthelayoutofthefilesonthefile

system.Additionally,deletingafilefromtheSolution

Exploreralsodeletesthefilefromtheharddrive.Youcan

alsoremoveaprojectfromtheSolutionExplorer,butthe

filesremainonthefilesystem.Bydefault,anysupporting

filesforafileinyourprojectarehidden,suchasresource

filesforWindowsFormprojects.Toviewtheextrafiles,click

ontheShowAllFilesbuttonintheSolutionExplorer

window.

ClassViewThiswindowdisplaysallthedatatypeswithina

project.Double-clickingonaclassname,method,variable,

interface,orotherdatatypetakesyoutothattype's

definitionwithinthesourcewindow.Youcancustomizethe

layoutofthiswindowbyclickingtheorganizetoolbar

button.Forinstance,selectingtheGroupbyTypeplacesall

classeswithinasinglegroup,andwithineachclassafolder

iscreatedforallmethods,variables,properties,delegates,

andotherlanguageconstructs.



ResourceWindowTheResourcewindowdisplaysany

resourcesthatyouhavecreatedforyourapplication.

However,theResourceWindowisusedforVisualC++

resourcefiles(.rc),whichmeansthatitisemptyforC#

projects.

PropertiesOtherwiseknownasthePropertyBrowser,the

PropertieswindowusesaPropertyGrid.NETcontroland

reflectiontechniquestoshowalistofpropertiesfora

selectedtype.Forinstance,selectingaButtoncontrol

withintheWindowFormDesignerdisplaystheproperties

fortheButtonclass,allowingyoutochangethemasyou

seefit.YoualsousethePropertieswindowtocreateevent

handlersforcontroleventsbyselectingthelightningbolt

iconwithinthePropertieswindowtoolbar.

DynamicHelpThefirstversionofVisualStudio.NET

introducedauniqueconceptofobtaininghelp,which

automaticallydisplaysMSDNhelpitemsbasedonthe

currentcontextyouareeditingin.Forinstance,clickingon

theclasskeywordwithinthesourcecodewindowdisplays

relevanttopicsassociatedwithcreatingandusingclasses.

ServerExplorerTheServerExplorerwindowdisplaysany

dataconnectionsthatyouhaveestablishedwithintheIDE,

allowingyoutoviewandeditdatabases.Forinstance,

installingSQLServerandcreatingdataconnectionstoa

particulardatabaseallowsyoutoeditthetables,perform

databasequeries,andeveneditstoredproceduresusing

theVisualStudio.NETQueryBuilderdesigner.Additionally,

theServerExplorerdisplayslocalWindows-specific

technologiesrelatedtothesystemsuchasperformance

counters,eventlogs,messagequeues,andservices.You

canaddtheseitemstoaWindowsFormapplication,andthe

necessary.NETobjectiscreatedtointeractwiththatitem.



ToolboxTheToolboxwindowcontainsallthecontrolsand

componentsthatyoucanuseinaWindowsapplication,

ASP.NETWebapplication,and.NETapplicationsthatusethe

.NETCompactFramework.Severaltabsareavailablewithin

thetoolbox,butyouseeonlythosethatarerelevanttothe

designeryouareworkingin.Inotherwords,ifyouare

creatingaWindowsFormapplication,theWebForms

Toolboxtabishiddenfromview.Toviewalltheavailable

tabsinthetoolbox,right-clickonitandselecttheShowAll

Tabsmenuitem.



PresetLayoutsandDeveloperProfiles

VisualStudio.NETshipswithseveraldefinedwindowlayouts

tailoredtoaparticulardeveloper'sstyleandexperiencelevel.

Toaccessthelistofprofiles,selecttheProfilestabfromthe

VisualStudio.NETstartpage.Thedefaultprofileisnamed

VisualStudioDeveloper,butyoucanchangetheprofileto

appearmorelikeVisualC++6.0,forinstance,bysettingthe

profiletoVisualC++DeveloperormorelikeVisualBasic6.0by

settingtheprofiletoVisualBasicDeveloper.Changingthese

profilesalsochangesthekeyboardscheme,windowlayout,and

helpfilter.



Docking

Adockingwindowisawindowthatisanchoredtoaparticular

areaoftheIDEsurroundingthemainsourceviewwindow.For

instance,theSolutionExplorerandClassViewwindowsare

dockedalongthetop-rightedgeoftheIDEwiththeProperties

windowandDynamicHelpalongthebottom-rightedge.Youcan

changethelocationofthewindowsbydraggingtheirtoolbars

anddroppingtheminalocation.Asyoudragthewindows,a

grayrectangleshowsthelocationofthewindowifitwere



droppedatthattime.Ifmultiplewindowsoccupythesame

space,atabcontrolallowsyoutotabbetweenthedifferenttool

windows.Toaddanewitemtoatabgroup,dragthetoolbarof

thewindowyouwanttodockontothetabgroups,andyousee

theoutlineofanewtab.Youcanalsocreateafloatingwindow,

whichisnotanchoredtotheIDE.Onthemaindevelopment

system,forinstance,youmightkeepafloatingoutputwindow

thatisdisplayedonasecondmonitoraswellasadebugwatch

window.



Auto-Hiding

Withsomanyavailabletoolwindows,theIDEcansoonget

cluttered,especiallyonmonitorsrunninginlowresolutions.The

VisualStudio.NETIDEallowsyoutoauto-hidewindows.Click

ontheupper-rightpush-pinbuttoninthetoolwindow'stitlebar

toauto-hidethatwindow.Whenyoudoso,thewindow

collapsestotheedgeoftheIDEandatabappearswithalabel

denotingthenameofthetoolwindow.Ifyouhoveryourmouse

overthetoolwindow,itslidesintoplace.Ifyouauto-hideatool

windowthatiswithinatabgroup,allthetabwindowswithin

thatgroupcollapse.



VisualStudio.NETToolbars

ThetoolbarswithinVisualStudio.NETarelogicallyorganizedby

thefunctionstheyperform.Youcanviewalistofallthe

availabletoolbarsbyright-clickingtheareaalongthetopofthe

IDE.Sometoolbarsautomaticallyappearwheneveryouopena

correspondingfileorobjectwithintheIDE.

Youcanchangetheappearanceandaddnewtoolbarbuttonsby

selectingTools,Customize.WithintheCustomizedialog,you

cancreateyourowncustomtoolbarsbyclickingontheNew

button.Ablanktoolbarappears,readyforyoutoaddbuttons.

Toaddanewtoolbarbutton,clickontheCommandstabwithin

theCustomizetoolbox.Commandsaregroupedaccordingto

theircategory,andselectingacategorydisplaysthelistof

associatedcommands.Afterfindingthecommandyouwant,

simplydraganddropitfromtheCommandtabtothetoolbar

thatyouwanttoplaceiton.Youcanalsoaddbuttonstothe

toolbarsdefinedbytheIDE.VisualStudio.NETfeaturesa

macro-processingfacilityusedforextensibility.Youcanassign

thesemacrostotoolbarbuttons.Toseethelistofdefined

macros,selecttheMacroscategory.



AppendixB..NETDebugging.Reference

Towriteanysignificantamountofcodewithoutevercreatinga

mistakeisanearimpossibletask.Infact,mostapplications

shiptocustomerswithsomedefectsstillintact.Knowinghowto

usethedebuggerinVisualStudio.NETwillhelpyoupinpoint

theproblemmoreeffectively.Thisappendixlooksatthevarious

methodstousewhiledebuggingaswellastheassociated

debuggertoolwindowsthatprovideadditionalinformationwhile

youfindproblemsinyourcode.



WorkingwithBreakpoints

Youusebreakpointstohalttheexecutionofyourprogramata

certainlocationinyourcodeinordertoinspectthevaluesof

anyvariablesinyourcodeaswellastoviewtheorderof

statementexecution,aprocessknownasstepping.Toadda

breakpointtoacertainline,clickintheleft-sidemarginofthe

sourcewindow.Areddotappearsatthatlocation,andthe

correspondingstatementishighlighted.Ifyoulaterwantto

jumptothesourcecodefilewhereacertainbreakpoint

appears,youcanusetheBreakpointstoolwindow,whichis

accessibleusingtheDebug,Windowsmenuitem.Youcanalso

usethiswindowtochangethepropertiesofthebreakpointifit

isconditional.



ConditionalBreakpoints

Youcanaddconditionalbreakpointsthatbreakonlywhena

certainconditionismet.Toaddaconditionalbreakpoint,rightclickinthesourcewindowatthelocationtoplacethe

breakpointandselectNewBreakpoint.WithintheNew

Breakpointdialog,clickontheConditionbutton.TheBreakpoint

Conditiondialogletsyouenteraexpressionthatisevaluated

eachtimetheprogramreachesthatbreakpoint.Ifthecondition

evaluatestotrue,thentheprogramishaltedatthebreakpoint

location.Anexampleofwherethisisusefulisaforloop.Ifyou

hadaforloopthatloopedmanytimes,butyouwereonly

interestedinviewingthestatementexecutionswhenthe

countervariablereachesacertainpoint,specifyabreakpoint

condition.Thefollowingcodeshowsaforloopwithalarge

rangespecifiedforthecounter.Tocreateaconditional

breakpointwhenthecounterisabove100,usetheexpressioni

>=100:



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Appendix A. Visual Studio .NET IDE

Tải bản đầy đủ ngay(0 tr)

×