C#学习笔记TreeView ClassWord文件下载.docx

上传人:b****6 文档编号:8435053 上传时间:2023-05-11 格式:DOCX 页数:14 大小:27.30KB
下载 相关 举报
C#学习笔记TreeView ClassWord文件下载.docx_第1页
第1页 / 共14页
C#学习笔记TreeView ClassWord文件下载.docx_第2页
第2页 / 共14页
C#学习笔记TreeView ClassWord文件下载.docx_第3页
第3页 / 共14页
C#学习笔记TreeView ClassWord文件下载.docx_第4页
第4页 / 共14页
C#学习笔记TreeView ClassWord文件下载.docx_第5页
第5页 / 共14页
C#学习笔记TreeView ClassWord文件下载.docx_第6页
第6页 / 共14页
C#学习笔记TreeView ClassWord文件下载.docx_第7页
第7页 / 共14页
C#学习笔记TreeView ClassWord文件下载.docx_第8页
第8页 / 共14页
C#学习笔记TreeView ClassWord文件下载.docx_第9页
第9页 / 共14页
C#学习笔记TreeView ClassWord文件下载.docx_第10页
第10页 / 共14页
C#学习笔记TreeView ClassWord文件下载.docx_第11页
第11页 / 共14页
C#学习笔记TreeView ClassWord文件下载.docx_第12页
第12页 / 共14页
C#学习笔记TreeView ClassWord文件下载.docx_第13页
第13页 / 共14页
C#学习笔记TreeView ClassWord文件下载.docx_第14页
第14页 / 共14页
亲,该文档总共14页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

C#学习笔记TreeView ClassWord文件下载.docx

《C#学习笔记TreeView ClassWord文件下载.docx》由会员分享,可在线阅读,更多相关《C#学习笔记TreeView ClassWord文件下载.docx(14页珍藏版)》请在冰点文库上搜索。

C#学习笔记TreeView ClassWord文件下载.docx

Syntax:

publicclassTreeView:

Control

Remarks:

TheNodescollectionholdsalltheTreeNodeobjectsthatareassignedtotheTreeViewcontrol.Thetreenodesinthiscollectionarereferredtoastheroottreenodes.Anytreenodethatissubsequentlyaddedtoaroottreenodeisreferredtoasachildnode.BecauseeachTreeNodecancontainacollectionofotherTreeNodeobjects,youmightfinditdifficulttodetermineyourlocationinthetreestructurewhenyouiteratethroughthecollection.YoucanparsetheTreeNode.FullPathstringbyusingthePathSeparatorstringvaluetodeterminewhereaTreeNodelabelbeginsandends.

YoucandisplayimagesnexttothetreenodesbyassigninganImageListtotheImageListpropertyandreferencingtheindexvalueofanImageintheImageListtoassignthatImage.Usethefollowingpropertiestoassignimages:

·

SettheImageIndexpropertytotheindexvalueoftheImagethatyouwanttodisplaywhenatreenodeisnotselected.

SettheSelectedImageIndexpropertytotheindexvalueoftheImagethatyouwanttodisplaywhenatreenodeisselected.

TheimagesreferencedbytheImageIndexandSelectedImageIndexpropertyvaluesarethedefaultimagesdisplayedbyallthetreenodesthatareassignedtotheNodescollection.IndividualtreenodescanoverridethedefaultimagesbysettingtheTreeNode.ImageIndexandTreeNode.SelectedImageIndexproperties.

Treenodescanbeexpandedtodisplaythenextlevelofchildtreenodes.TheusercanexpandtheTreeNodebyclickingtheplus-sign(+)button,ifoneisdisplayednexttotheTreeNode,oryoucanexpandtheTreeNodebycallingtheTreeNode.Expandmethod.ToexpandallthechildtreenodelevelsintheNodescollection,calltheExpandAllmethod.YoucancollapsethechildTreeNodelevelbycallingtheTreeNode.Collapsemethod,ortheusercanpresstheminus-sign(-)button,ifoneisdisplayednexttotheTreeNode.YoucanalsocalltheTreeNode.Togglemethodtoalternatebetweentheexpandedandcollapsedstates.

Treenodescanoptionallydisplaycheckboxes.Todisplaythecheckboxes,settheCheckBoxespropertyoftheTreeViewtotrue.TheCheckedpropertyissettotruefortreenodesthatareinacheckedstate.

Note:

SettingtheTreeNode.CheckedpropertyfromwithintheBeforeCheckorAfterCheckeventcausestheeventtoberaisedmultipletimesandcanresultinunexpectedbehavior.Forexample,youmightsettheCheckedpropertyintheeventhandlerwhenyouarerecursivelyupdatingthechildnodessothattheuserdoesnothavetoexpandandcheckeachoneindividually.Topreventtheeventfrombeingraisedmultipletimes,addlogictoyoureventhandlerthatonlyexecutesyourrecursivecodeiftheActionpropertyoftheTreeViewEventArgsisnotsettoTreeViewAction.Unknown.Foranexampleofhowtodothis,seetheExamplesectionoftheAfterCheckorBeforeCheckevents.

YoucanchangetheappearanceoftheTreeViewcontrolbysettingsomeofitsdisplayandstyleproperties.SettingShowPlusMinustotruedisplaysaplus-signorminus-signbuttonnexttoeachTreeNodethatcanbeexpandedorcollapsed,respectively.SettingtheShowRootLinespropertytotruecausestheTreeViewtodisplaylinesthatjoinalltheroottreenodestogether.YoucandisplaylinesthatconnectchildtreenodestotheirrootnodebysettingtheShowLinespropertytotrue.SettingtheHotTrackingpropertytotruechangestheappearanceofthetreenodelabelsasthemousepointerpassesoverthem.Whenhot-tracked,thetreenodelabelstakeontheappearanceofahyperlink.YoucanalsocompletelycustomizetheappearanceoftheTreeViewcontrol.Todothis,settheDrawModepropertytoavalueotherthanTreeViewDrawMode.NormalandhandletheDrawNodeevent.

WhensettingtheCheckBoxes,Scrollable,ImageIndex,andSelectedImageIndexpropertiesatruntime,theTreeViewhandleisrecreated(seeControl.RecreateHandle)toupdatethecontrol'

sappearance.Thiscausesalltreenodestobecollapsed,exceptfortheselectedTreeNode.

Constructor:

publicTreeView():

InitializesanewinstanceoftheTreeViewclass.

Properties:

1、AllowDrop:

publicvirtualbool型,Getsorsetsavalueindicatingwhetherthecontrolcanacceptdatathattheuserdragsontoit.Thedefaultisfalse.

NotestoInheritors:

WhenoverridingtheAllowDroppropertyinaderivedclass,usethebaseclass'

sAllowDroppropertytoextendthebaseimplementation.Otherwise,youmustprovidealltheimplementation.YouarenotrequiredtooverrideboththegetandsetaccessorsoftheAllowDropproperty;

youcanoverrideonlyoneifneeded.

2、Anchor:

publicvirtualAnchorStyles型,Getsorsetstheedgesofthecontainertowhichacontrolisboundanddetermineshowacontrolisresizedwithitsparent.ThedefaultisTopandLeft.

UsetheAnchorpropertytodefinehowacontrolisautomaticallyresizedasitsparentcontrolisresized.Anchoringacontroltoitsparentcontrolensuresthattheanchorededgesremaininthesamepositionrelativetotheedgesoftheparentcontrolwhentheparentcontrolisresized.

Youcananchoracontroltooneormoreedgesofitscontainer.Forexample,ifyouhaveaFormwithaButtonwhoseAnchorpropertyvalueissettoTopandBottom,theButtonisstretchedtomaintaintheanchoreddistancetothetopandbottomedgesoftheFormastheHeightoftheFormisincreased.

TheAnchorandDockpropertiesaremutuallyexclusive.Onlyonecanbesetatatime,andthelastonesettakesprecedence.

WhenoverridingtheAnchorpropertyinaderivedclass,usethebaseclass'

sAnchorpropertytoextendthebaseimplementation.Otherwise,youmustprovidealltheimplementation.YouarenotrequiredtooverrideboththegetandsetaccessorsoftheAnchorproperty;

youcanoverrideonlyoneifneeded.

3、AutoScrollOffset:

publicvirtualPoint型,GetsorsetswherethiscontrolisscrolledtoinScrollControlIntoView.Thedefaultistheupper-leftcornerofthecontrol.

4、AutoSize:

publicvirtualbool型,ThisAPIsupportsthe.NETFrameworkinfrastructureandisnotintendedtobeuseddirectlyfromyourcode.Thispropertyisnotrelevantforthisclass.

5、BackColor:

publicoverrideColor型,Getsorsetsthebackgroundcolorforthecontrol.ThedefaultisthevalueoftheDefaultBackColorproperty.

6、Bottom:

publicint型,Getsthedistance,inpixels,betweenthebottomedgeofthecontrolandthetopedgeofitscontainer'

sclientarea.

ThevalueofthispropertyisequaltothesumoftheToppropertyvalue,andtheHeightpropertyvalue.

TheBottompropertyisaread-onlyproperty.YoucanmanipulatethispropertyvaluebychangingthevalueoftheToporHeightpropertiesorcallingtheSetBounds,SetBoundsCore,UpdateBounds,orSetClientSizeCoremethods.

7、BorderStyle:

public 

BorderStyle型,Getsorsetstheborderstyleofthetreeviewcontrol.

Whenthe 

BorderStyle 

propertyissetto 

Fixed3D,the 

TreeView 

hasasunken,three-dimensionalappearance.Todisplayaflat,thinborderaroundthe 

control,setthe 

propertyto 

FixedSingle.

8、CanFocus:

publicbool型,Getsavalueindicatingwhetherthecontrolcanreceivefocus.

Inorderforacontroltoreceiveinputfocus,thecontrolmusthaveahandleassignedtoit,andtheVisibleandEnabledpropertiesmustbothbesettotrueforboththecontrolandallitsparentcontrols,andthecontrolmustbeaformorthecontrol'

soutermostparentmustbeaform.

9、CanRaiseEvents:

protectedoverridebool型,Determinesifeventscanberaisedonthecontrol.

IfthiscontrolisbeinghostedasanActiveXcontrol,thispropertywillreturnfalseiftheActiveXcontrolhasitseventsfrozen.

10、CanSelect:

publicbool型,Getsavalueindicatingwhetherthecontrolcanbeselected.

ThispropertyreturnstrueiftheSelectablevalueofSystem.Windows.Forms.ControlStylesissettotrue,iscontainedinanothercontrol,thecontrolitselfisvisibleandenabled,andallitsparentcontrolsarevisibleandenabled.

TheWindowsFormscontrolsinthefollowinglistarenotselectableandwillreturnavalueoffalsefortheCanSelectproperty.Controlsderivedfromthesecontrolsarealsonotselectable.

Panel·

GroupBox·

PictureBox·

ProgressBar·

Splitter·

Label·

LinkLabel(whenthereisnolinkpresentinthecontrol)

11、Capture:

publicbool型,Getsorsetsavalueindicatingwhetherthecontrolhascapturedthemouse.

Whenacontrolhascapturedthemouse,itreceivesmouseinputwhetherornotthecursoriswithinitsborders.Themouseistypicallyonlycapturedduringdragoperations.

Onlytheforegroundwindowcancapturethemouse.Whenabackgroundwindowattemptstodoso,thewindowreceivesmessagesonlyformouseeventsthatoccurwhenthemousecursoriswithinthevisibleportionofthewindow.Also,eveniftheforegroundwindowhascapturedthemouse,theusercanstillclickanotherwindow,bringingittotheforeground.

Whenthemouseiscaptured,shortcutkeysshouldnotwork.

12、CheckBoxes:

publicbool型,Getsorsetsavalueindicatingwhethercheckboxesaredisplayednexttothetreenodesinthetreeviewcontrol.Thedefaultisfalse.

AcheckboxisdisplayedtotheleftofboththetreenodelabelandtreenodeImage,ifany.Checkboxesallowtheusertoselectmorethanonetreenodeatatime.

WhentheCheckBoxespropertyofaTreeViewissettotrue,andtheStateImageListpropertyisset,eachTreeNodethatiscontainedintheTreeViewdisplaysthefirstandsecondimagesfrom

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 幼儿教育 > 幼儿读物

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2