10. µøµ¡³q¥Î«¬±±¨î¶µ¡G²Ä¤@³¡¥÷

°£¤F²Ä¤T³¹´y­zªº¤º«Ø±±¨î¶µ¤§¥~¡Aµøµ¡³q¥Î±±¨î¶µ¤]±`¼sªx¦a³QVisual Basic©Ò¨Ï¥Î¡C¥¦­Ì¦p¦¹´¶¤Î¤Æªº¥D­n­ì¦]¬O¥Ñ©ó¥¦­Ì¤ñ¨ä¥LÃþªº±±¨î¶µ§ó®e©ö«P¦¨Ãþ¦üµøµ¡³nÅ骺²£¥Í¡CÁ|¨Ò¨Ó»¡¡A¨Ï¥ÎÃþ¦üÀÉ®×Á`ºÞ¥ª¤èªºTreeView±±¨î¶µ©M¥k¤èªºListView±±¨î¶µ¯à¥ß§Y¦a´£¿ôÀÉ®×Á`ºÞªº¨Ï¥ÎªÌ¡A¦p¦¹¥i¥H«Ø¥ß¸û¿Ë©Mªº¨Ï¥ÎªÌ¤¶­±¡C

µøµ¡³q¥Î±±¨î¶µ­º¨£©óWindows 95¡C³Ìªì³o¨Ç±±¨î¶µ¥]§tTreeView¡BListView¡BImageList¡BToolbar¡BStatusBar¡BTabStrip¥H¤ÎSlider±±¨î¶µ¡CVisual Basic 4-²Ä¤@­Ó32¦ì¤¸ª©¥»ªºµ{¦¡»y¨¥-´£¨Ñ¥H¯à¦s¨ú¸ê®ÆªºOLE Custom Control¡]OCX¡^¬°¤@¤j¯S¦â¡CÀHµÛ²Ä¤@ª©ªºµo¦æ¡A·L³n¶}©l¤j¶q¥Í²£´X­Ó·sªº¡B¾Ö¦³§ó±j¤j¥\¯àªº³q¥Î±±¨î¶µ¦b­ì©lªºª©¥»¤¤¡C¦ý¬OOCXÀHµÛVisual Basic 5ªº¨ì¨Ó¡]©M¥¦¥»¨­ªº¤T­Óservice packs¡^¤w¸g¤£¦A°µ­«¤jªº§ï¨}¤F¡A³oªí¥Ü¨Ï¥ÎVisual Basicªºµ{¦¡³]­p®vµLªk¨Ï¥Î§ó·sªº±±¨î¶µ¦b¥L­ÌªºÀ³¥Îµ{¦¡¤W¡]·sªºAnimation©MUpDown±±¨î¶µ¨Ò¥~¡^¡Cª½¨ì³Ìªñ¡A¦pªG­n¨Ï¥Î¸û·sªº±±¨î¶µ©Î¥R¤À¦a¹B¥Î­ì©l±±¨î¶µªº¯à¤O¡AVisual Basicªºµ{¦¡¶}µoªÌ¥²¶·¨Ì¾a¨ó¤O¼t°Ó¶}µoªºActiveX±±¨î¶µ©Î¨Ï¥Î½ÆÂøªºAPIµ{¦¡¡C

Visual Basic 6¤w¸g¸É±Ï¤F³o­Ó°ÝÃD¡A¥¦´£¨Ñ¤F±z©Ò»Ý­nªº¤u¨ã¡A¥H«K¹B¥Î©Ò¦³²{¦¨±±¨î¶µªº¥\¯à¡C¤Ö¼Æªºµøµ¡³q¥Î±±¨î¶µ¤´µM¯Ê¤Ö·sª©ªºOCXÀɮס]¤×¨ä¬OIP¦ì§}±±¨î¶µ¡^¡A¦ý¬O¦bµ´¤j¦h¼Æªº±¡ªp¤U¡A±z¤£»ÝÁʶR¥ô¦óÃB¥~ªº¦Û­q±±¨î¶µ¡A´N¯à«Ø¥ß²{¥N¤Æªº¨Ï¥ÎªÌ¤¶­±¡C

¤j³¡¤Àªºµøµ¡±±¨î¶µ¥]§t©óMsComCtl.ocxÀɮסA³o­ÓÀÉ®×¥]§t©Ò¦³­ì¨Óªº³q¥Î±±¨î¶µ¡A¦A¥[¤WImageCombo±±¨î¶µ¡C¥t¥~¤@­ÓMsComCt2.ocxÀɮסA¥]§t¥t¥~¤­­ÓÃB¥~±±¨î¶µ¡GAnimation¡BUpDown¡BMonthView¡BDateTimePicker©MFlatScrollBar¡C³o¨â­ÓÀɮפÀ§O¬°Visual Basic 5¤¤ªºComCtl32.ocx©MComCt232.ocxÀɮתº§ó·sª©¥»¡CVisual Basic 6¤£·|¨ú¥Nª©ªºOCXÀɮסA¦Ó¥BÁÙ¥i¥H©M¥­ªº»PVisual Basic 5¦@¦s¡A¨Ã¥B¬Û®e©ó¥Î¸Óª©©Ò¶}µoªºÀ³¥Îµ{¦¡¡C

Visual Basic 6¤]¥]§t¤ä´©¥t¤@­Ó³q¥Î±±¨î¶µ¡] CoolBar±±¨î¶µ ¡A·|¦b²Ä¤Q¤@³¹¤¶²Ð¡^OCXÀÉ®×—ComCt332.ocx¡C¥H«eµ{¦¡¶}µo¤H­û¥²¶·±q·L³nªººô¯¸¥h¤U¸ü¥¦¡A¦ý¬O³o­ÓÀɮץثe¤w¸g¥]§t¦bVisual Basic®M¸Ë³nÅ餤¤F¡C

Visual Basic 6¤¤ªºOCXÀɮצ³¤@­Ó«Ü¦³½ìªº¯S¦â¡C¸ûªºComCtl32.ocx©MComCt232.ocxÀɮ׳q±`¥R·íVisual Basic©M¥]§t¹ê»Ú¹B§@ªº±±¨î¶µµ{¦¡½Xªº¨t²ÎDLLÀɤ§¶¡ªº´C¤¶¡A¦ý·sª©«h¨ã³Æ¿W¦Û©Ê¡A¨Ã¥B¥]§t¾Þ§@±±¨î¶µ¥²­nªºµ{¦¡½X¡C¤ð±e¸mºÃªº¡A·sª©ªºÀɮ׸û­ì¥ýªº¬°¤j¡ÐMsComCtl.ocx¶W¹L1MB¤j¤p¡Ð¦ý¬O³o¼Ë·|²¤ÆVisual BasicÀ³¥Îµ{¦¡´²¼½ªº½ÆÂø©Ê¨Ã¥B¸ò¨ä¥L¦w¸Ë¦b¨Ï¥ÎªÌ¹q¸£¤Wªºµ{¦¡½Ä¬ð¸û¤p¡C

¥»³¹»¡©ú¤F©Ò¦³¥]§t¦bMsComCtr.ocxªºµøµ¡±±¨î¶µªº¯S¦â¡A¤U¤@³¹±N²[»\MsComCt2.ocx©MComCt232.ocx¤ºªº©Ò¦³±±¨î¶µ¡C¬°¤F´ú¸Õ¥Ø«eªºµ{¦¡½X¡A­º¥ý¥²¶·¨Ï±±¨î¶µ¯à°÷¥X²{Visual BasicÀô¹Ò¡C¬°¤F¹F¦¨³o­Ó¥Øªº¡A¥ý±q±M®×¿ï³æ¤¤°õ¦æ ³]©w¤Þ¥Î¤¸¥ó «ü¥O¡]©Î«ö¤UCtrl+T²Õ¦XÁä¡^¡AÅã²{ ³]©w¤Þ¥Î¤¸¥ó ¹ï¸Ü¤è¶ô¡A¦p¹Ï10-1©Ò¥Ü¡AµM«á¿ï¨ú±z­nªºOCX¬ÛÃö¿ï¶µ¡A¦p¹Ï10-2©Ò¥Ü¡C

·í±z¶i¤JVisual Basic 6Àô¹Ò¡A­Y±zªº±M®×¬O¥Ñ¥ý«eª©¥»ªºµ{¦¡©Ò«Ø¥ß¡B¥B¥]§tª©ªºµøµ¡±±¨î¶µ¡A±N·|¼u¥X¤@­Ó°T®§¤è¶ô¸ß°Ý±z¬O§_­n§ó·s¬°¸û·sª©ªº±±¨î¶µ¡A¬°¤F¨Ï²{¦sªºÀ³¥Îµ{¦¡¹F¨ì³Ì¤jªº¬Û®e©Ê¡A¥i¥H¨M©wÄ~Äò¨Ï¥Îª©ªº±±¨î¶µ¡A±z¥i¥H¦b ±M®×ÄÝ©Ê ªº¹ï¸Ü¤è¶ô¤¤ªº ¤@¯ë ­¶ÅÒ¤W¨ú®ø³o­Ó¤É¯ÅActiveX±±¨î¶µªºÄµ§i°T®§¡C


¡@

¹Ï10-1 ³]©w¤Þ¥Î¤¸¥ó¹ï¸Ü¤è¶ô¡A¥]§t©Ò¦³ªºµøµ¡±±¨î¤¸¥óOCX¿ï¶µ¡C


¡@

¹Ï10-2 ¤u¨ã¦C¤¤ªº³q¥Î±±¨î¶µ¡C

ImageList±±¨î¶µ
¡@

ImageList±±¨î¶µ³Ì¤jªº¥Î³~¬O°µ¬°¹Ï®w¡A¦¬¯Ç³Q¨ä¥L±±¨î¶µ¡]¨Ò¦pTreeView¡BListView¡BTabStrip¡BImageComboµ¥¡^©Ò¨Ï¥Îªº¼v¹³»P¹Ï¥Ü¡C¤]¦]¬°¦p¦¹¡A¦b¤¶²Ð¨ä¥L±±¨î¶µ¤§«e¡A±o¥ý±´°Q³o­Ó±±¨î¶µ¡CImageList±±¨î¶µ¦b°õ¦æ¶¥¬q¬O¬Ý¤£¨£ªº¡A¥B¬°¤FÅã¥Ü¨ä©Ò¥]§tªº¥ô¤@±i¼v¹³¡A±z»Ý­n±N¤§´yø©óForm¡BPictureBox±±¨î¶µ©ÎImage±±¨î¶µ¤W¡B©Î¬Æ¦Ü±N¤§»P¨ä¥L±±¨î¶µ²£¥ÍÃöÁp¡C

¨Ï¥ÎImageList±±¨î¶µ§@¬°¨ä¥L±±¨î¶µªº¼v¹³¶°¦X¦³³\¦h¦n³B¡C¨Æ¹ê¤W¡A°²­Y¤£¨Ï¥Î³o­Ó±±¨î¶µªº¸Ü¡A«h»Ý­n¦b°õ¦æ¶¥¬q³z¹LLoadPicture¨ç¼Æ±N©Ò»Ý­nªº¼v¹³¦ÛºÏºÐ¤¤¸ü¤J¡A¦p¦¹¤@¨Ó¡A±N¨Ïªí³æ¸ü¤Jªº®É¶¡ÅܺC¡C¦b³]­p®É´Á«K±N©Ò¦³»Ý­nªº¼v¹³¸ü¤JImageList±±¨î¶µ¡A¨Ã±N¤§«ü¬£µ¹¨ä¥L±±¨î¶µ©Î¹B¥Î©óµ{¦¡µ¥³£¬O§ó²³æ¥B¦³®Ä²vªº¡C

¼W¥[¹Ï¹³
¡@

ImageList±±¨î¶µ´£¨Ñ¤FListImages¶°¦Xª«¥ó¡A¦Ó¦¹¶°¦Xª«¥ó¥]§t³\¦hListImageª«¥ó¡A¨C¤@­ÓListImage¶µ¥Ø¦U¦³¨ä¿W¥ßªº¼v¹³¡C»P¨ä¥L¶°¦Xª«¥ó¬Û¦P¡A¨C­Ó¿W¥ßªºListImageª«¥ó¬Ò¥i¥Ñ¯Á¤Þ©Î¯Á¤ÞÁä¡]°²­Y¦³ªº¸Ü¡^¨Óªí¥Ü¡A¨ä¤¤¯Á¤Þ¬°¼Æ¦r§ÎºA¡B¯Á¤ÞÁä«h¬°¦r¦ê§ÎºA¡C¨C­ÓListImageª«¥ó¥i¦³¤@­Ó¼v¹³¡A¨ä®æ¦¡¥i¬°¤U¦C¤§¤@¡GÂI°}¹Ï¡].bmp¡^¡B¹Ï¥Ü(.ico)¡B´å¼Ð(.cur)¡BJPEG(.jpg)¡BGIF(.gif)¡CVisual Basic 5¤¤ªºImageList±±¨î¶µ¤¤¨Ã¥¼´£¨Ñ³Ì«á¨âºØ®æ¦¡¡C

©ó³]­p¶¥¬q¥[¤J¼v¹³
¡@

©ó³]­p¶¥¬q¥[¤J¼v¹³¬O¥ó«Ü®e©öªº¨Æ¡C§âImageList±±¨î¶µ©ñ¸m©óªí³æ¡AµM«á¦b±±¨î¶µ¤W«ö¤U·Æ¹«¥kÁä¡A¨Ã¦b§Ö±¶¿ï³æ¤¤¿ï¨ú ÄÝ©Ê ¿ï¶µ¡A±µµÛ¤Á´«¨ì ¼v¹³ ­¶ÅÒ¡A¦p¹Ï10-3©Ò¥Ü¡CµM«á¥u»Ý­n«ö¤U ´¡¤J¹Ï¤ù «ö¶s¡A¨Ã¦ÛºÏºÐ¤¤¬D¿ï±z­nªº¼v¹³§Y¥i¡C¤£¹L¡AÀ³¸Ó­n¬°¨C­Ó¼v¹³¨ú­Ó¯Á¤ÞÁä­È¡A¦p¦¹¤@¨Ó¡A©¹«á«K¯à¥¿½T¦a«ü©w¬Y­Ó¼v¹³¡C¦]¬°¥i¯à¦b¥¼¨Ó·|¼W¥[©Î´î¤Ö¼v¹³¡A³o¥i¬O·|¼vÅT¨ì¨C­Ó¼v¹³ªº¯Á¤Þ­Èªº¡C·íµM¡A³o¨Ç¯Á¤ÞÁä­È¬O¤£¥i­«½Æªº¡C¦pªG¼v¹³»Ý­n¦³¤å¦rªº´y­z©Î¥]§t¨ä¥L¸ê°Tªº¸Ü¡A¥i¥H±N³o¨Ç¤å¦r«ü¬£µ¹¼v¹³ªºTagÄÝ©Ê¡CVisual Basic¤£·|ª½±µ¨Ï¥ÎTagÄÝ©Ê¡A¦]¦¹¥i¥H©ñ¤ß¦a¦s©ñ¥ô¦ó¤å¦r¸ê®Æ¡C


¡@

¹Ï10-3 ImageList±±¨î¶µÄÝ©Ê­¶ªº¹Ï¤ù­¶ÅÒ ¡C

¥[¤JListImages¶°¦Xª«¥óªº¼v¹³¥i¥H¬O¥ô·N¤j¤pªº¡C¦pªG¤£¨Ï¥Î¨ä¥L³q¥Î±±¨î¶µ¤¤ªº¹Ï¹³¡A²Ä¤@±i¤§«áªº©Ò¦³¹Ï¹³±N³Q©µ®i¬°²Ä¤@³¹¹Ï¹³ªº¤j¤p¡C¦pªG­nÅã²{ªí³æ¤W¡]¦pPictureBox©ÎImage±±¨î¶µµ¥¡^ªº¹Ï¹³¡A±N¤£·|¦³³oºØ°ÝÃD¡C

¦pªGImageList±±¨î¶µ¤£¥]§t¥ô¦ó¼v¹³ªº¸Ü¡A±z¥i¥H¦b ÄÝ©Ê ¹ï¸Üµøµ¡¤¤ªº ¤@¯ë ­¶ÅÒ¤¤³]©w¼v¹³ªº¤j¤p¡C°²­Y¦b±±¨î¶µ¤w¥]§t¤@±i¥H¤Wªº¼v¹³®É¡A¶i¦æ¤W­zªº°Ê§@¬O·|³y¦¨¿ù»~ªº¡C

©ó°õ¦æ¶¥¬q¥[¤J¼v¹³
¡@

©ó°õ¦æ¶¥¬q¥[¤J¼v¹³¥²¶·³z¹LListImages¶°¦Xª«¥óªºAdd¤èªk¡A»yªk¦p¤U¡G

Add([Index], [Key], [Picture]) As ListImage

¦pªG¬Ù²¤Index°Ñ¼Æ®É¡A«h¼v¹³·|¥[¦b¶°¦Xª«¥óªº³Ì«á¡C¤U¦Cµ{¦¡±N«Ø¥ß¤@­Ó·sªºListImage¶µ¥Ø¨Ã¥]§t¤@±i¦ÛºÏºÐ¤¤¸ü¤JªºÂI°}¹Ï¡G

Dim li As ListImage
Set li = ImageList1.ListImages.Add(, "Cut", _
    LoadPicture("d:\bitmaps\cut.bmp"))

°£«D¦³»Ý­n¦b­è­è«Ø¥ß¤§ª«¥óªºTagÄݩʤ¤¦s©ñ¤å¦r¡A§_«h¨Ã¤£»Ý­n±NAdd¤èªk©Ò¶Ç¦^ªº­È«ü¬£µ¹¤@­ÓListImageª«¥ó¡C¬Æ¦Ü¡A¤]¤£»Ý­nListImageª«¥ó´N¯à³]©w¼v¹³ªºTagÄÝ©Ê¡A½Ð¨£¤U¨Ò¡G

With ImageList1.ListImages.Add(, "Cut", LoadPicture("d:\bitmaps\cut.bmp"))
    .Tag = "The Cut icon"
End With

­n§R°£¤@­ÓListImageª«¥ó¡]¥]§t¦b³]­p©Î°õ¦æ¶¥¬q©Ò¥[¤J¡^¡A¥i³z¹LListImages¶°¦Xª«¥óªºRemove¤èªk¡C

' You can use a numerical index or a string key
' to remove the associated image.
ImageList1.ListImages.Remove "Cut"

±z¤]¥iÂǥѶ°¦Xª«¥óªºClear¤èªk¤@¦¸²¾°£©Ò¦³ªº¼v¹³¡G

' Remove all images.
ImageList1.ListImages.Clear

³z¹LImageListªºImageWidth»PImageHeightÄÝ©Ê¡A¥i¥H±oª¾¦s©ñ©ó±±¨î¶µ¤¤ªº¼v¹³¤j¤p¡C³o¨âºØÄݩʪº³æ¦ì¬°Pixel¡A¥B¥u¦³·íListImages¶°¦Xª«¥ó¬OªÅ¶°¦X®É¤è¯à§ïÅܨä­È¡A¤@¥¹¼W¥[¼v¹³«á¡A´N¦¨¤F°ßŪÄÝ©Ê¡C

Â^¨ú»PÅã¥Ü¼v¹³
¡@

°²­Y§âImageList±±¨î¶µ³sµ²¦Ü¨ä¥L³q¥Î±±¨î¶µ®É¡A³q±`µL¶·¦Ò¼{¦p¦óÅã¥Ü¼v¹³ªº°ÝÃD¡A¦]¬°µ{¦¡·|¦Û°Ê¦a¶i¦æ³o¨Ç¤u§@¡C¦ý­Y­n¤â°Ê¦aÅã¥Ü³o¨Ç¼v¹³ªº¸Ü¡A´N¥²¶·¤F¸Ñ¤@¨ÇÃö©óImageList±±¨î¶µ»PListImageª«¥óªºÄÝ©Ê»P¤èªk¡C

Â^¨ú¼v¹³
¡@

¨C­ÓListImageª«¥ó¬Ò¦³­ÓPictureÄÝ©Ê¡A³o­ÓÄÝ©Ê«ü¥XÄÝ©óListImageª«¥óªº¹Ï§Î¡A¦]¦¹±`¥i±N¦¹ÄÝ©Ê­È«ü¬£µ¹PictureBox©ÎImageµ¥±±¨î¶µ¡A¨Ò¦p¡G

Set Picture1.Picture = ImageList1.ListImages("Cut").Picture

³q±`¡A·í­n¨Ï¥ÎPictureBox©ÎImage±±¨î¶µªºPictureÄݩʮɡA¤]¥i¥H§ï¥ÎListImageª«¥óªºPictureÄÝ©Ê¡A¨Ò¦p¤U¨Ò¡G

' Save an image to a disk file.
SavePicture ImageList1.ListImages("Cut").Picture, "C:\cut.bmp"
' Display an image on the current form, zooming it by a factor
' of 4 along the X-axis, and 8 along the Y-axis.
With ImageList1
    PaintPicture .ListImages("Cut").Picture, 0, 0, _
        ScaleX(.ImageWidth, vbPixels) * 4, ScaleY(.ImageHeight, vbPixels) * 8
End With

³z¹LPaintPicture¤èªk¡A¥i¦bªí³æ©ÎPictureBox±±¨î¶µ¤WÅã¥ÜListImageª«¥ó¡A¤]¥i¥H¿é¥X¨ìPrinterª«¥ó¤W¦C¦L¥X¨Ó¡CÃö©óPaintPicture¤èªkªº¸Ô²Ó»¡©ú¡A½Ð°Ñ¾\ ²Ä¤G³¹ ¡C

ListImageª«¥ó¤]¥]§tExtractIcon¤èªk¡A³o­Ó¤èªk¥i¥H²£¥Í¤@­Ó¹ïÀ³¨ä¼v¹³ªº¹Ï¥Ü¡A¨Ã±N¦¹¹Ï¥Ü¶Ç¦^µ¹©I¥sªÌ¡C¦]¦¹·í»Ý­n¹Ï¥Ü®É¡A¥i¥H¨Ï¥Î¦¹¤èªk¡A¨Ò¦p¡G

Form1.MouseIcon = ImageList1.ListImages("Pointer").ExtractIcon

»P¨ä¥L¼Ð·Ç¶°¦Xª«¥ó¤£¦Pªº¬O¡AListImages¶°¦Xª«¥ó¤¤ªº¯Á¤ÞÁä­È¬O¦³¤À¤j¤p¼gªº¡A·N«ä¬O»¡¡A¡uPointer¡v»P¡upointer¡v¬O¥þµM¤£¦Pªº¡C

²£¥Í³z©ú¼v¹³
¡@

ImageList±±¨î¶µÁÙ¦³­ÓMaskColorÄÝ©Ê¡A¥Î¨Ó¨M©w¦óºØÃC¦â­n§@¬°¾B¸n¡C¨ä¹w³]­È¬°¦Ç¦â¡]&HC0C0C0¡^¡A¤£¹L±z¥i¥H³z¹L¨âºØ¤è¦¡§ïÅÜ¥¦¡G©ó³]­p¶¥¬q¦b ÄÝ©Ê ¹ï¸Ü¤è¶ôªº ¦â±m ­¶ÅÒ¥i§ïÅܨä­È¡A©Î¦b°õ¦æ¶¥¬q³z¹Lµ{¦¡¨Ó§ïÅÜ¡C

¤£¹L¡A­Y­n¨Ï¥Î¾B¸n¨Ó¶i¦æø¹Ï°Ê§@®É¡AÁÙ±o½T©wUseMarkColorÄݩʭȬ°True¡]³o¤]¬O¹w³]­È¡^¤~¦æ¡CÂÇ¥ÑÄݩʹï¸Ü¤è¶ôªº ¤@¯ë ­¶Åҩε{¦¡½X¥i¥H§ïÅܤ§¡G

' Make white the transparent color.
ImageList1.MaskColor = vbWhite
ImageList1.UseMaskColor = True

¨Ï¥ÎDraw¤èªk
¡@

ListImageª«¥ó´£¨ÑDraw¤èªk¨Óø¹Ï¡A¨ä»yªk¦p¤U¡G

Draw hDC, [x], [y], [Style]

¨ä¤¤¡AhDC¬°ªí³æ¡BPictureBox±±¨î¶µ©ÎPrinterª«¥óªº¸Ë¸m¥N¸¹¡A¦Óx»Py¬O¼v¹³¦ì¦b¥Ø¼Ðª«ªº®y¼Ð¡]³æ¦ì¬°pixel¡^¡Astyle­È¥i¯à¬°¡G0-imlNormal¡]¹w³]­È¡A¦b¤£§ïÅܼv¹³ªº±¡ªp¤UÅã¥Ü­ì¹Ï¡^¡F1-imlTransparent¡]¨Ï¥ÎMaskColorÄݩʨӶi¦æ¾B¸n§@¥Î¡^¡F2-imlSelected¡]¨Ï¥Î¨t²Î°ª«G«×¦â±m¨ÓÅã¥Ü¸Ó¹Ï¡^¡F3-imlFocus¡]»PimlSelected¬Û¦P¡A¦ý·|²£¥ÍÃä®Ø®ÄªGªí¥Ü¸Ó¹Ï³Q¿ï¨ú¡^¡AÁ|¨Ò¦p¤U¡G

' Show an image in the upper left corner of a PictureBox control.
ImageList1.ListImages("Cut").Draw Picture1.hDC, 0, 0

«Ø¥ß²Õ¦X¼v¹³
¡@

ImageList±±¨î¶µÁÙ¥i¥H±N¨â´T¿W¥ßªº¼v¹³¡]¤w¦s¦b©ó¦U¦ÛªºListImageª«¥ó¤¤¡^²Õ¦X¦¨¤@´T·sªº²Õ¦X¹Ï¡C«Ø¥ß²Õ¦X¹Ïªº¤èªk¬°Overlay¡C¹Ï10-4Åã¥Ü¨â´T¿W¥ßªº¼v¹³¡A¦Ó«á±N¤§²Õ¦X¦¨·sªº¼v¹³¡G

PaintPicture ImageList1.ListImages(1).Picture, 0, 10, 64, 64
PaintPicture ImageList1.ListImages(2).Picture, 100, 10, 64, 64
PaintPicture ImageList1.Overlay(1, 2), 200, 10, 64, 64


¡@

¹Ï10-4 ¨Ï¥ÎOverlay²£¥Íªº®ÄªG

Overlay¤èªk§@¥Î®É¥i¨Ï¥ÎMarkColorÄݩʨӧ@¬°¼v¹³²Õ¦X®Éªº¾B¸n¡A¦]¦¹±z¥²¶·½T©wUseMarkColorÄݩʭȬ°True¡C

TreeView±±¨î¶µ
¡@

TreeView±±¨î¶µ¥i¯à¬O¨Ï¥ÎªÌ¼ô±xªº¤@­Óµøµ¡³q¥Î±±¨î¶µ¡A¦]¬°¦bÀÉ®×Á`ºÞ¤¤´N¥i¨£¨ì¡C°ò¥»¤W¡ATreeView±±¨î¶µ¥iªí¹F¸ê®Æ¶µ¥Øªº¶¥¼h©Ê¡C¨C­Ó¶µ¥Ø®Çªº¥[¸¹ªí¥Ü¨ä©³¤U¦³¤@­Ó¥H¤Wªº¤l¶µ¥Ø¡C¦³¤l¶µ¥Øªº¸ê®Æ¶µ¥i³Q®i¶}¨ÓÅã¥Ü©Ò¦³¤l¸ê®Æ¶µ¡A¥ç¥i¦¬°_¥H«KÁôÂ䧡C¨Ï¥ÎªÌ¥i¥æ´À¦a¶i¦æ³o¼Ëªº¦æ¬°¡A©Î³z¹Lµ{¦¡¥ç¥i¡C

Visual Basic 6©ÒªþªºTreeView±±¨î¶µ¬Û¸û©óª©¦Ó¨¥¦³³\¦hªº§ï¶i¡A¥B¦b¨C­Ó¶µ¥Ø®Ç´£¨Ñ®Ö¿ï¤è¶ô¨Ã¥i¿ï¨ú¾ã¦C¡C¬Æ¦Ü©ó¨C­ÓNodeªº²ÊÅé¡B«e´º¦â¡B­I´º¦âµ¥¥i¦³¤£¦Pªº³]©w¡C

TreeView±±¨î¶µ¥]§t¤@­ÓNode¶°¦Xª«¥ó¡A¨ä¥]§t©Ò¦³¦b¦¹±±¨î¶µ¤ºªºNodeª«¥ó¡C¨C­Ó¿W¥ßªºNodeª«¥ó©|¥]§t³\¦h¥Î¨Ó¨M©w±±¨î¶µ¥~Æ[ªºÄÝ©Ê¡C¤@¯ë¦Ó¨¥¡ATreeView±±¨î¶µ¦³¤@­Ó³æ¤@ªº®ÚNodeª«¥ó¡A¦ý¤]¥i¥H«Ø¥ß¦h­Ó®ÚNodeª«¥ó¡C

³]©w³]­p¶¥¬qÄÝ©Ê
¡@

¦bªí³æ¤W©ñ¸mTreeView±±¨î¶µ¤§«á¡A«ö¤U·Æ¹«¥kÁä¨Ã¿ï¨ú ÄÝ©Ê ¿ï¶µ·|¥X²{ ÄÝ©Ê­¶ ¡]¦p¹Ï10-5©Ò¥Ü¡^¡C·íµM¤]¥i¥H©ó°õ¦æ®É¦A³]©w¬ÛÃöªºÄÝ©Ê¡AµM¦Ó³oºØ±¡ªp¬O¤£¦h¨£ªº¡C

StyleÄݩʼvÅT±±¨î¶µªº¹Ï§Îªí¥Ü¤¸¯À¡CTreeView±±¨î¶µ¥i¥HÅã¥Ü¥|ºØ¹Ï§Îªí¥Ü¤¸¯À¡G¨C­ÓNodeª«¥óªº¤å¦r¡BÅã¥Ü¹Ï¤ù¡B¦bNodeª«¥ó®Çªº¥[¸¹©Î´î¸¹¡]¥Î¨Óªí¥Ü¸`ÂI¬O®i¶}©Î¦¬°_ª¬ºA¡^¡AÁÙ¦³Nodeª«¥ó»P¨ä¤lª«¥ó¶¡ªº³sµ²½u¡CStyleÄݩʭȦ@¦³¤K­Ó¡A¨C­Ó­Èªí¥Ü¤W­z¹Ï¥Ü©Òªí¥Ü¤¸¯Àªº¦UÃþ²Õ¦X¡Cµ´¤j³¡¥÷¬O±Ä¥Î¹w³]­È¡]7-tvwTreelinesPlusMinusPictureText¡^¨Óªí¥Ü©Ò¦³ªº¹Ï§Îªí¥Ü¤¸¯À¡C


¡@

¹Ï10-5 TreeView±±¨î¶µÄÝ©Ê­¶ªº¤@¯ë­¶ÅÒ

LineStyleÄݩʪí¥Ü³sµ²½uªºÅã¥Ü¼Ë¦¡¡C0-tvwTreeLines­È¡]¹w³]­È¡^ªí¥Ü¦b®ÚNodeª«¥ó¶¡¤£Åã¥Ü³sµ²½u¡A¦Ó1-tvwRootLines­È«hÅã¥Ü®Ú¸`ÂI¤§¶¡ªº½u¡A¥H¤Î¦P¼h¸`ÂI©M¥¦­Ìªº¤÷¸`ÂI¤§¶¡ªº½u¡CIndentationÄݩʪí¥Ü¸`ÂI¶¡¶Z¡A³æ¦ì¬°pixel¡C

LabelEditÄݩʪí¥Ü¨Ï¥ÎªÌ¥i§_­×§ï¸`ÂIªºÅã¥Ü¤å¦r¡C¦pªG¨ä­È¬°0-tvwAutomatic¡]¹w³]­È¡^¡A«h¨Ï¥ÎªÌ©ó°õ¦æ®É¥i¿ï¨ú¸`ÂI«á¦AÂI¿ï¤§¨Ó­×§ï¨äÅã¥Ü¤å¦r¡F¦pªG¨ä­È¬°1-tvwManual¡A¨º­Y­n­×§ï¸`ÂI¤å¦r¡A¥²¶·Âǥѵ{¦¡½X¤¤ªºStartLabelEdit¤èªk¤~¦æ¡C

ImageList¤U©Ô¿ï³æ¥Î¨Ó¿ï¾Ü¸`ÂI¼v¹³¦ì¦b­þ­ÓImageList±±¨î¶µ¤º¡C¤U©Ô¿ï³æ·|¦C¥X¦b¦¹ªí³æ¤Wªº©Ò¦³ImageList±±¨î¶µ¡C


¤p¯µ³Z

°£¤F¦b³]­p¶¥¬q«K«ü©w¦nTreeView±±¨î¶µ¡]©Î¨ä¥L±±¨î¶µ¡^ªºImageListÄÝ©Ê¥~¡A¤]¥i©ó°õ¦æ®É¶i¦æ³]©w¡Aµ{¦¡¦p¤U¡G

Private Sub Form_Load()
    Set TreeView1.ImageList = AnotherForm.ImageList1
End Sub

Âǥѳo­Ó§Þ¥©¡A±z«KµL¶·¦b¨C­Óªí³æ¤W¬Ò©ñ¸mImageList±±¨î¶µ¡A¥u»Ý±N©Ò¦³»Ý­nªº¼v¹³¦s©ñ©ó¤@­ÓImageList±±¨î¶µ¡A¨Ã©ñ¸m©ó¤@­Óªí³æ§Y¥i¡C¦p¦¹¤@¨Ó¡A¥i´î¤p°õ¦æÀɪº¤j¤p¤]¸`¬Ù°õ¦æ®É©Ò»Ýªº°O¾ÐÅé»P¸ê·½¡C


HideSelectioÄݩʨM©w·íTreeView±±¨î¶µ¥¢¥hµJÂI®É¡A¬O§_³Q¿ï¨úªº¸`ÂI¤´¬O°ª«G«×ªº¡CPathSeparatorÄݩʪí¥Ü­þ­Ó¦r¤¸©Î¦r¦ê­n³Q¨Ï¥Î¦bFullPathÄÝ©Ê¡C¹w³]ªºÄݩʭȬ°¡u\¡v¦r¤¸¡C¨Ò¦p¡A­Y¦³­Ó®Ú¸`ÂIÅã¥Ü¬°¡uRoot¡v»P¨ä¤l¸`ÂIÅã¥Ü¬°¡uFirstChild¡v¡A«h¨ä¤l¸`ÂIªºFullPathÄÝ©Ê­È«h¬°¡uRoot\FirstChild¡v¡C

SortedÄݩʪí¥Ü±±¨î¶µ¤ºªº¸`ÂI¬O§_­n¦Û°Ê¦a¥H¦r¥À¶¶§Ç¨Ó±Æ§Ç¡C»¡©ú¤â¥U¤¤¿òº|¤F¤@­Ó­«­n»¡©ú¡G³o­ÓÄݩʶȼvÅT®Ú¸`ÂIªº±Æ§Ç¡A¦Ó¤£·|¼vÅT¦¸¤@¼h¤l¸`ÂIªº±Æ§Ç¡C¦pªG±z­n©Ò¦³ªº¤ÀªK¬Ò¬O¤w±Æ§Çªº¡A¥²¶·³]©w¨C­Ó¸`ÂIªºSortedÄݩʬ°True¡C

Visual Basic 6©ÒªþªºTreeView±±¨î¶µ¼W¥[¤F´X­Ó¦³½ìªºÄÝ©Ê¡CFullRowSelectÄÝ©Ê­È­Y¬°True¡Aªí¥Ü¥u­nÂI¿ï¸`ÂI¸Ó¦Cªº¥ô·N¦ì¸m«K¥i¿ï¨ú¸Ó¸`ÂI¡C¨ä¹w³]­È¬°False¡Aªí¥Ü¥u¦³ÂI¿ï¸Ó¸`ÂI©Î¨ä¥[´î¸¹®É¤~¯à¿ï¨ú¤§¡C

¦pªGCheckBoxesÄݩʬ°True¡A¦b¨C­Ó¸`ÂI®Ç·|¥X²{¤@­Ó®Ö¿ï¤è¶ô¡A¨Ï¥ÎªÌ¥i¥HÂǦ¹¿ï¾Ü¦h­Ó¸`ÂI¡C

¦b¹w³]±¡ªp¤U¡A±z»Ý­nÂùÀ»¸`ÂI¤è¯à®i¶}©Î¦¬°_¦¹¶µ¥Ø¡]©ÎÂI¿ï¥[´î¸¹¡^¡A¥B¨C­Ó¸`ÂIªº®i¶}©Î¦¬°_¬Ò¬O¤¬¤£¬Û¼vÅTªº¡CµM¦Ó­Y±NSingleSelÄݩʳ]©w¬°True®É¡A±±¨î¶µªº¦æ¬°´N¦³¤FÅܤơG­Y­n®i¶}©Î¦¬°_¸`ÂI¡A¥u»ÝÂI¿ï¤§§Y¥i¡C¦¹¥~¡A¤@¥¹®i¶}¬Y­Ó¸`ÂI¡A«h¨ä¥L¸`ÂI±N·|¥þ¼Æ¦¬°_¡C

ScrollÄݩʨM©wTreeView±±¨î¶µ¬O§_­nÅã¥Ü««ª½©Î¤ô¥­±²¶b¡C¹w³]­È¬°True¡A¦ý¥i¥H±N¤§³]©w¬°False¥H«K¨ú®ø±²¶bªºÅã¥Ü¡]µM¦Óµ§ªÌ§ä¤£¥X¥ô¦ó»Ý­n¨ú®øªº²z¥Ñ¡^¡C

³Ì«á¡AHotTrackingÄÝ©Ê¥i«Ø¥ßÃþ¦üWebªº¥~Æ[¡C­Y³]©w¦¹Äݩʬ°True¡A·í·Æ¹«²¾¨ì¸`ÂI¤W¤è®É¡A·Æ¹«¹Ï¥Ü·|Åܦ¨¤âª¬¥B¸`ÂI¤å¦r·|¥X²{©³½u¡C

°õ¦æ¶¥¬qªº¹B§@
¡@

¬°¤F­n§¹¥þ´x±±TreeView±±¨î¶µ¡AÁÙ¥²¶·¾Ç·|Nodes¶°¦Xª«¥ó»PNodeª«¥óªºÄÝ©Ê»P¤èªk¡C

¼W¥[Nodeª«¥ó
¡@

TreeView±±¨î¶µ¦³­Ó¯ÊÂI´N¬O¤£¯à¹³ListBox»PComboBox±±¨î¶µ¤@¼Ë©ó³]­p¶¥¬q¼W¥[¸ê®Æ¶µ¥Ø¡C¶È¯à¦b°õ¦æ¶¥¬qÂÇ¥ÑNodes¶°¦Xª«¥óªºAdd¤èªk¼W¥[¸ê®Æ¶µ¡CAdd¤èªkªº»yªk¦p¤U¡G

Add([Relative],[Relationship],[Key],[Text],[Image],[SelectedImage]) As Node

Relative»PRelationshipªí¥Ü·s¼W¥[ªº¸`ÂI¦ì¸m¡C¯Á¤ÞÁ䬰¦¹·sNode¦bNodes¶°¦Xª«¥óªº¦r¦êªí¥Ü¦¡¡AText¬°Åã¥Ü©ó¨ä¤Wªº¤å¦r¡A¦ÓImageªí¥ÜÅã¥Ü©ó¸`ÂI®Çªº¼v¹³¦bÃöÁpªºImageList±±¨î¶µ¤¤ªº¯Á¤Þ¡CSelectedImageªí¥Ü·í¸`ÂI³Q¿ï¨ú®Éªº¼v¹³¦bÃöÁpªºImageList±±¨î¶µ¤¤ªº¯Á¤Þ¡C¨Ò¦p¡A­Y­n¥ÎTreeView«Ø¥ß¦p¦PÀÉ®×Á`ºÞ¤¤ªº¥Ø¿ýµ²ºc®É¡AÃþ¦üªºµ{¦¡½X¦p¤U¡G

Dim nd As Node
Set nd  = Add(, , ,"C:\System", "Folder", "OpenFolder")

¬°¤F¦w¸m³o­Ó·sªºNode¦b¾ã­ÓTree¸Ì­±«ü©wªº¦ì¸m¤W¡A¥²¶·¦b«e­±´£¨Ñ¨â­Ó°Ñ¼Æ¡C²Ä¤@­Ó°Ñ¼Æ©ú½Tªº«ü¥X¦³­Ó¸g¥Ñ¼Æ­È¯Á¤Þ©Î¨ä¦r¦êªí¥Ü¦¡ÃÒ¹ê½T©w¦s¦b¤@­Ó¶µ¥Ø¦bNodes¶°¦X¤¤¡F²Ä¤G­Ó°Ñ¼Æ»¡©úNode©M¨ä¥L¬Û¦üNode¤§¶¡ªºÃö«Y¡C¦p¦¹ªºÃö«Y¥i¥H¬O·sªºNodeÅܦ¨¨ä¥L¬Û¦üNodeªº²Ä¤@­Ó¶µ¥Ø0-tvwFirst¡Ð´«¥y¸Ü»¡¡A¥¦Åܦ¨¨ä¬Û¦üNode¤¤ªº²Ä¤@­Ó¡C©ÎªÌ³o­ÓÃö«Y¤]¥i¥H¬O1-tvwLast¡]³o­Ó·sªºNodeÅܦ¨¨ä¥L¬Û¦üNodeªº³Ì«á¤@­Ó¡^¡F¦Ó2-tvwNext¡]¹w³]­È¡A·sªºNode·|ª½±µªþ¥[¦b¦P¼Ë¼h¯Å¤Wªº¤U¤@­Ó¬Û¦üNode¤W¡^¡F3-tvwPrevious·sªºNode±N´¡¤J¦Ü¦P¼Ë¼h¯Åªº¬Û¦üNode«e­±¡^¡F©ÎªÌ³Ì«á¤@­Ó4-tvwChild¡]³o­Ó·sªºNode±NÅܦ¨¨ä¬Û¦üNodeªº¤UÄÝ¡A¦Ó¥B·|±Æ¦b¨ä¥L¤UÄݤ§«á¡^¡C

³o¸Ì¦³¤@­Ó¦X²zªº¡B¾Ö¦³¤@­ÓMDBÀÉ®×µ²ºcªºTreeView±±¨î¶µ¨Ò¤l¡Ð¥Ñ¦¹¥i¬Ý¥X¥¦©Ò§t¦³ªº¸ê®Æªí»P¦U¸ê®ÆªíªºÄæ¦ì¡C³o­Ó°Æµ{¦¡ªº²Ä¤G­Ó°Ñ¼Æ¥i±µ¨üTreeView±±¨î¶µ¡AÂǦ¹¥i¥H®e©ö¦a¦bÀ³¥Îµ{¦¡¤¤­«½Æ§Q¥Î¡C²Ä¤T­Ó°Ñ¼Æªí¥Ü¬O§_­nÅã¥Ü¨t²Î¸ê®Æªí¡G

Sub ShowDatabaseStructure(MdbFile As String, TV As TreeView, _
    ShowSystemTables As Boolean)
    Dim db As DAO.Database, td As DAO.TableDef, fld As DAO.Field
    Dim nd As Node, nd2 As Node
    ' Clear the current contents of the TreeView control.
    TV.Nodes.Clear
    ' Open the database.
    Set db = DBEngine.OpenDatabase(MdbFile)
    ' Add the root Node, and then expand it to show the tables.
    Set nd = TV.Nodes.Add(, , "Root", db.Name, "Database")
    nd.Expanded = True

    ' Explore all the tables in the database.
    For Each td In db.TableDefs
        ' Discard system tables if user isn't interested in them.
        If (td.Attributes And dbSystemObject) = 0 Or ShowSystemTables Then
            ' Add the table under the Root object.
            Set nd = TV.Nodes.Add("Root", tvwChild, , td.Name, "Table")
            ' Now add all the fields.
            For Each fld In td.Fields
                Set nd2 = TV.Nodes.Add(nd.Index, tvwChild, , _
                    fld.Name, "Field")
                Next
            End If
    Next
    db.Close
End Sub

ª`·N³o­Ó¨Ò¤l¤£¤¹³\¥ô¦ó¿ù»~ªº¾Þ§@¡G¦pªG³o­ÓÀɮפ£¦s¦b©Î¬O«DªkªºMDB¸ê®ÆÀÉ¡A³o­Ó¿ù»~·|¶Ç¦^µ¹©I¥sªÌ¡C³q±`·|®i¶}TreeView±±¨î¶µªºRootª«¥ó¥H«K¸`¬Ù¨Ï¥ÎªÌ¦A«ö¤@¤U·Æ¹«Áä¡C³o­Ó¨Ò¤l·|ÂǥѧâRoot Nodeª«¥óªºExpandedÄݩʳ]¬°True¨Ó¹F¦¨¦¹®ÄªG¡C

¥~Æ[»P¥iµø©Ê
¡@

¸g¥Ñ³]©w¨äForeColor¡BBackColor©MBoldÄÝ©Ê¥i±±¨î³æ¿WNodeª«¥óªº¥~Æ[¡A³o­Ó®ÄªG¦p¹Ï10-6©Ò¥Ü¡C¦¹·sªº¯S©Ê¥i§ïÅܧó¦hÃö©ó¨C­ÓNodeªº¸ê®Æ¡C¤@¯ë¦Ó¨¥¡A¥i¥H¦b¼W¥[¶µ¥Ø¨ìNodes¶°¦X¤¤®É³]©w³o¨ÇÄÝ©Ê¡G

With TV.Nodes.Add(, , , "New Node")
    .Bold = True
    .ForeColor = vbRed
    .BackColor = vbYellow
End With


¡@

¹Ï10-6 ForeColor¡BBackColor©MBoldªºNodeª«¥óÄÝ©Ê©ÒÅã¥Üªº®ÄªG¡A¥]§tTreeView±±¨î¶µªºCheckboxesÄÝ©Ê¡C

¨C­ÓNodeª«¥ó³£¥Ñ¤T­Ó¬ÛÃöªº¹Ï¹³©Ò²Õ¦X¡A¦Ó¥BNodeªº¹ê»Úª¬ºA¨M©w¸Ó¹Ï¹³¬O§_®i¥Ü¡CImageÄݩʳ]©w¡B¶Ç¦^¹w³]¹Ï¹³ªº¯Á¤Þ­È¡FSelectedImageÄÝ©Ê«h­t³dNode¿ï©w®É¨Ï¥Îªº¹Ï¹³¯Á¤Þ­È¡FExpandedImageÄÝ©Ê«h­t³dNode©Òµo®iªº¹Ï¹³¯Á¤Þ­È¡C¥i¸g¥ÑNode¶°¦X¤¤ªºAdd¤èªk³]©w«e¨â­ÓÄÝ©Ê¡A¦ý¬O¥²¶·¦b¼W¥[¶µ¥Ø¨ì¶°¦X¤§«á¡A¤~¯à©ú½T¦a³]©wEnpandedImageÄÝ©Ê¡C

¸g¥Ñ¬d¸ßVisibleÄÝ©Ê¥i±oª¾¤@­Ó¯S©wªºNode²{¦b¬O§_¬°¥i¨£ªº¡CNode¶µ¥Ø¯à°÷³Q¬Ý¨£¬O¦]¬°¥¦¬OTree¦¬°_ªº¤äÂI©Î¦]¬°¥¦³Q±²°Ê¨ì¬Ý±o¨£ªº¦a¤è¡C³o­ÓÄݩʬO°ßŪªº¡A¦ý¬O¥i¸g¥ÑEnsureVisible¤èªk±j­¢§ïÅܳo­ÓNodeªº¥i¨£©Ê¡C

' Scroll the TreeView, and expand any parent Node if necessary.
If aNode.Visible = False Then aNode.EnsureVisible

¥iÂÇ¥ÑTreeViewªºGetVisibleCount¤èªk¨Ó±oª¾¦³¦h¤Ö¥i¬Ý¨£ªºNode¦b³o­Ó±±¨î¶µ¤¤¡C

¦³¨âºØ¤èªk¥h±oª¾¦b±±¨î¶µ¤¤ªºNode¬O§_¥¿³Q¿ï¾Ü¡ÐÂǥѬd¸ß¥¦ªºSelectedÄÝ©Ê©Î¥h´ú¸ÕTreeViewªºSelectedItemÄÝ©Ê¡G

' Check whether aNode is the Node currently selected (two
' equivalent ways).
' First way:
If aNode.Selected Then MsgBox "Selected"
' Second way:
If TreeView1.SelectedItem Is aNode Then MsgBox "Selected"

' Make aNode the currently selected Node (two equivalent ways).
' First way:
aNode.Selected = True
' Second way:
Set TreeView1.SelectedItem = anode

Åã¥ÜNodeªº¸ê°T
¡@

¨Ï¥ÎªÌ´Á±æ·í¥L­ÌÂI¿ïTreeView±±¨î¶µ¤WªºNodeª«¥ó®É¡Aµ{¦¡«K·|¦Û°Ê°õ¦æ—Á|¨Ò¨Ó»¡¡A·|Åã¥Ü¤@¨Ç¸Óª«¥óªº°T®§¡C¬°¤F±oª¾Node¦ó®É³QÂI¿ï¡A¥²¶·¥hIJµoNodeClick¨Æ¥ó¡C¥iÂÇ¥ÑIndex©ÎKeyÄÝ©Ê¥H±oª¾­þ­ÓNode³QÂI¿ï¡C¨å«¬ªº±¡§Î¬O±NNodeªº¸ê°TÀx¦s¦b¤@­Ó¦r¦ê°}¦C©ÎUDT¡]¨Ï¥ÎªÌ¦Û©w§ÎºA¡^¶µ¥Ø¤W¡G

Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    ' info() is an array of strings that hold nodes' descriptions.
    lblData.Caption = info(Node.Index) 
End Sub

NodeClick¨Æ¥ó·|»P¨Ï¥ÎªÌÂI¿ïTreeView±±¨î¶µ®É©Ò¤ÞµoªºClick¨Æ¥ó¤£¦P¡C«e¤@­Ó¨Æ¥ó¬O¥u¦³·í¨Ï¥ÎªÌ¿ï¨ú¤@­ÓNodeª«¥ó®É¤~·|IJµo¡C

¥ý«eªºµ{¦¡½X¥i¯à·|¦³°ÝÃD¡G¤@¯ë¨Ó»¡¡A¤@­ÓNodeª«¥óªºIndexÄݩʬO¤£¸Ó³Q«H¥ôªº¡A¦]¬°·|¦]¨ä¥LNodeª«¥ó±qNode¶°¦X¤¤²¾°Ê¦Ó§ïÅÜ¡C°ò©ó³o­Ó²z¥Ñ¡AÀ³¸Ó¨Ì¾a±M¤@ªºKeyÄÝ©Ê¡A¸ÓÄݩʤ£·|¦]¶°¦X¤¤ªºNode¼W¥[¦Ó­×§ï¡CÁ|­Ó¨Ò¤l¡A¥i¨Ï¥ÎKeyÄÝ©Ê¥h´M§ä¤@­Ó¥Î¨ÓÀx¦sNode¬ÛÃö¸ê®Æªº¼Ð·Ç¶°¦Xª«¥ó¤¤ªº¶µ¥Ø¡CÀH®Ñ¥úºÐ¤ºªºBrowMdb.vbp±M®×¥]¬AShowDatabaseStructure­×¥¿ª©¡A¨ä·|¥HTreeView±±¨î¶µÅã¥Ü©Ò¦³Field¤ÎTableDefª«¥óªºÄÝ©Ê»P¯S½è¡A¦p¹Ï10-7©Ò¥Ü¡G


¡@

¹Ï10-7 ·L³nJet¸ê®Æ®wªº·§²¤ÂsÄý¡C

½s­×Node¤å¦r
¡@

¦b¹w³]ªº±¡ªp¤U¡A¨Ï¥ÎªÌ¥i¥HÂI¿ïNodeª«¥ó¶i¤J½s¿è¼Ò¦¡©M¶¡±µ¦a¥h­×§ïNodeª«¥óªºTextÄÝ©Ê¡C¦pªG±z¤£³ßÅw³o¼Ë¡A¥i¥H­«³]LabelEditÄݩʬ°1-tvwManual¡C¦p¦¹¤@¨Ó¡A±NÅܦ¨¥u¦³¸g¥Ñ°õ¦æStartLabelEdit¤èªk¤~¯à¶i¤J½s¿è¼Ò¦¡¡C

¤£ºÞLabelEditÄݩʪº­È¬O¦h¤Ö¡A³£¯à®·®»¨ì¨Ï¥ÎªÌ¶}©l­×§ïTextÄݩʭȪº®É¶¡¡]ÂÇ¥ÑBeforeLabelEdit¨Æ¥ó¡^¡C·í³o­Ó¨Æ¥óIJµo®É¡A¥i¥H³z¹LTreeViewªºSelectedItemÄݩʨӱoª¾­þ­ÓNode³Q¿ï¨ú¡A¦Ó¥BÁÙ¥i¥HÂǥѱNCancelÄݩʳ]¬°Trueªº¤è¦¡¨Ó¨ú®ø³o¨Ç°Ê§@¡G

Private Sub TreeView1_BeforeLabelEdit(Cancel As Integer)
    ' Prevent the root Node's Text property from editing.
    If TreeView1.SelectedItem.Key = "Root" Then Cancel = True
End Sub

¦P¼Ë¦a¡A¤]¥i¥H§ä¥X¨Ï¥ÎªÌ¦ó®Éµ²§ô½s¿è©MÂÇ¥ÑÂ^¨úAfterLabelEdit¨Æ¥ó±oª¾Textªº·s­È¡C¤@¯ë¥i¥Î¦¹¨Æ¥ó¨ÓÀˬd©Ò¿é¤Jªº¸ê®Æ¬O§_¬°¥¿½T¨Ã¥i±µ¨üªº¡CÁ|¨Ò¨Ó»¡¡A¥i¥H¥Ñ¤U­±ªºµ{¦¡¨Ó©Úµ´ªÅªº¦r¦ê¡G

Private Sub TreeView1_AfterLabelEdit(Cancel As Integer, _
    NewString As String)
    If Len(NewString) = 0 Then Cancel = True
End Sub

¨Ï¥Î®Ö¿ï¤è¶ô
¡@

­n¦C¥XTreeView±±¨î¶µ¤¤¨C­ÓNodeªº¿ï¨ú¤è¶ô¡A¥²¶·³]CheckboxesÄݩʬ°True¡AµL½×¬O¦b³]­p¶¥¬q©Î¦b°õ¦æµ{¦¡¡C¥i¥H¨Ï¥ÎCheckedªºÄݩʨӬd¸ß©Î­×¥¿¦U­ÓNodeªºª¬ºA¡G

' Count how many Node objects are checked, and then reset all check boxes.
Dim i As Long, SelCount As Long
For i = 1 To TreeView1.Nodes.Count
    If TreeView1.Nodes(i).Checked Then
        SelCount = SelCount + 1
        TreeView1.Nodes(i).Checked = False
    End If
Next

¥u­nÂǥѼg¤J±±¨î¶µªºNodeChecked¨Æ¥ó¨Ó½T©wNode¡A±N¥i¥H±j¨î°õ¦æ¸û¬°ÄYÂÔªº±±¨î¶µ¡C¦pªG­×§ïNodeªºCheckedÄݩʪºµ{¦¡½X¡A«h³o­Ó¨Æ¥ó±N¤£·|±Ò°Ê¡G

Dim SelCount As Long     ' The number of selected items
Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
    ' Display the number of selected Nodes.
    If Node.Checked Then
        SelCount = SelCount + 1
    Else
        SelCount = SelCount _ 1
    End If
    lblStatus = "Selected Items = " & SelCount
End Sub

¤p¯µ³Z

¦pªG·Q­n¹w¨¾¨Ï¥ÎªÌ­×§ïNodeª«¥óªºCheckedª¬ºA¡A«h¤£¯àÀH·N¦a¥HNodeCheck¨Æ¥ó¨Ó­«³]CheckedÄÝ©Ê¡A¦]¬°¸g¹LÅܰʪº©Ò¦³ÄݩʱN·|ÀHµÛ¨Æ¥óªº¹Lµ{¦Ó¿ò¥¢¡C¥iÂǵۼW¥[ªí³æ¤WTimerªº±±¨î¶µ©M¼g¤Jµ{¦¡½X¨Ó¸Ñ¨M³o­Ó°ÝÃD¡G

Dim CheckedNode As Node            ' A form-level variable
Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
    ' Prevent the user from checking the first Node.
    If Node.Index = 1 Then
        ' Remember which Node has been clicked on.
        Set CheckedNode = Node
        ' Let the Timer routine do the job.
        Timer1.Enabled = True
    End If
End Sub
Private Sub Timer1_Timer()
    ' Reset the Checked property, and then go to sleep.
    CheckedNode.Checked = False
    Timer1.Enabled = False
End Sub

¦pªGTimerªºIntervalÄݩʬO³]¸m¦b¤@­Ó·¥¤pªº­Èªº¸Ü¡A¦p10²@¬í¡A·|¦³¸û¦nªº®Ä²v¡C


²`¤J§Þ¥©
¡@

TreeView±±¨î¶µ¾Ö¦³«Ü¦nªº¼u©Ê¡A¦ý¬O¦³®É­Ô±z¥²¶·ÂǧU§ó²`¤Jªº§Þ¥©©M¤Ö¥Î¨Çª½Ä±¨Ó¾ÞÁa¥¦¡C

»Ý­n®É¤è¸ü¤JNode
¡@

²z½×¤W¨Ó»¡¡A±z¯à°÷Ū¨ú¨ì¤W¤dµ§TreeView±±¨î¶µ¶µ¥Ø¡C¦Ó¹ê»Ú¤W¡A¥uŪ¨ú´X¦Êµ§ªº¶µ¥Ø«K·|¨Ïµ{¦¡ºC±o¤£¤Ó¯à§Ô¨ü¡CÁ|¨Ò¨Ó»¡¡AŪ¨úµ²ºc¥Ø¿ý¦ÜTreeView±±¨î¶µ¡AÀÉ®×Á`ºÞ·|³o¼Ë¤l°µ¡G³o­Ó²³æªº¥ô°È·|»Ý­n«Ü¦hªº®É¶¡¨Ó±½´y¨t²ÎªºµwºÐ¡A¦ý¤£¯àÅý¨Ï¥ÎªÌµ¥­Ô¦p¦¹ªøªº®É¶¡¡C¦b³oºØ±¡ªp¤U¡A±o±Ä¨ú»Ý­n®É¤~¸ü¤Jªº¤èªk¡C

»Ý­n®É¤~¸ü¤Jªº¤èªkªí¥Ü·í¨ä¤W¼h³Q®i¶}¡A¦³»Ý­nÅã¥Ü¤U¼h¶µ¥Ø¤~¼W¥[Nodesª«¥ó¡C±z¯àÂÇ¥ÑÂ^¨úTreeView±±¨î¶µªºExpand¨Æ¥ó¨Ó¨M©w¦ó®É®i¶}¤@­ÓNode¡]¤]¥iÂǥѸӱ±¨î¶µªºCollapse¨Æ¥ó§ä¥X¤@­ÓNodeª«¥ó¦ó®É¦¬¦^¡^¡C¦Ü©ó¨ä¥LÃø³B²zªº²Ó³¡¬O­nÅý¨Ï¥ÎªÌ¤F¸Ñ¤@­ÓNode¦p¦ó¾Ö¦³¤@­Ó©Î¦h­Ó¤UÄݪ«¥ó¡A¦Ó¤£»Ý­n¹ê»Ú¥h¼W¥[¥¦­Ì¡C´«¥y¸Ü»¡¡A§Ú­Ì»Ý­nÅã¥Ü¥[¸¹¡A­YNode¶µ¥Ø¦³¤U¼h¸ê®Æ®É¡C

­nÃÒ©úTreeView³q¥Î±±¨î¶µ¯à°÷¦bNode®ÇÅã¥Ü¤@­Ó¥[¸¹¦ÓµL»Ý¤lNodes¬O«Ü®e©öªº¡G¥u­n°õ¦æÀÉ®×Á`ºÞµM«á¬Ý¨ì¡u³nºÐ¾÷A: ¡v¡F¨º´N¬O¤F¡A§Y¨Ï¥¦¨S¦³¤l¥Ø¿ý¦b³oºÏºÐ¤¤¡]§Y¨Ï¨S¦³¥ô¦óªººÏ¤ù¦bA¼Ñ¤¤¡^¡C¤£©¯¦a¡A¦pªG¨S¦³¼W¥[¤UÄÝNodes¡A«h®i¥Ü¤@­Ó¥[¸¹ªº¯à¤O¨Ã¥¼²[»\¦bVisual Basic¤ºªþªºOCXÀɤ¤¡A¦]¦Ó»Ý­n¨ÇAPIµ{¦¡¡CµM¦Ó¡A¦³­Ó§Þ¥©¨Ã¤£»Ý­n¥ô¦óAPI¡C

¬°¤F¦bNode®ÇÅã¥Ü¤@­Ó¥[¸¹¡A¥²¶·°µªº´N¬O¥h¼W¥[¤@­Ó¤UÄÝNode¡Cµ§ªÌ±N¤§ºÙ¬°¥é³yªº¤lNode¡C¥²¶·¥Î¤@­Ó²M·¡ªº¤èªk³]­p¤@­Ó¥é³yªºNode¶µ¥Ø—Á|¨Ò¨Ó»¡¡A±N¯S©wªºText©ÎTagÄݩʼƭȰµ±Æ§Ç¡C·í¤@­ÓNode²×©ó³Q®i¶}ªº®É­Ô¡Aµ{¦¡·|½T©w¸ÓNode¦³­Ó¥é³yªº¤UÄݶµ¥Ø¡C¦p¦¹¤@¨Ó¡A³o­Óµ{¦¡½X·|²¾°£³o­Ó¥é³yªº¤lNode¦Ó¥B¼W¥[©Ò¦³¯u¥¿ªº¤lNodes¡C¦p±z©Ò¬Ý¨ìªº¡A³o­Ó§Þ¥©¬Û·í²©ú¡AµM¦Ó§¹¦¨¥¦»Ý¥]§t¤@¨Ç·¥­«­nªºµ{¦¡½X¡C

¹Ï10-8¬°½d¨Òµ{¦¡°õ¦æªº¹Ï§Î¡C¥¦§¹¾ãªºµ{¦¡½X¦bÀH®Ñ¥úºÐ¤¤¡A©Ò¥Hµ§ªÌ¥u»¡©úÃöÁä³B¡C³oºØ§Î¦¡¥]¬AtvwDir¡]TreeView±±¨î¶µ¡^©M¨Ï¥ÎFileSystemObject¨ÓÀò±o³o­Ó¥Ø¿ýµ²ºc¡C


¡@

¹Ï10-8 ¥Ø¿ýÂsÄý¾¹µ{¦¡¥¿¦bŪ¨ú©Ò»ÝªºTreeView Nodes¡C

¤U¦CªºDirRefreshµ{§Ç·|¦bForm_Load¨Æ¥ó¤¤¤Þ¥Î¡G

Private Sub DirRefresh()
    Dim dr As Scripting.Drive
    Dim rootNode As node, nd As Node
    On Error Resume Next
    
    ' Add the "My Computer" root Node (expanded).
    Set rootNode = tvwDir.Nodes.Add(, , "\\MyComputer", _
        "My Computer", 1)
    rootNode.Expanded = True
    ' Add all the drives; display a plus sign beside them.
    For Each dr In FSO.Drives
        ' Error handling is needed to account for not-ready drives.
        Err.Clear
        Set nd = tvwDir.Nodes.Add(rootNode.Key, tvwChild, dr.Path & "\", _
            dr.Path & " " & dr.VolumeName, 2)
        If Err = 0 Then AddDummyChild nd
    Next
End Sub
Sub AddDummyChild(nd As node)
    ' Add a dummy child Node if necessary.
    If nd.Children = 0 Then
        ' Dummy nodes' Text property is "***".
        tvwDir.Nodes.Add nd.index, tvwChild, , "***"
    End If
End Sub

¥ý«eªºµ{§Ç½T«O³oºØ§Î¦¡·|Åã¥Ü¡u§Úªº¹q¸£¡vRoot Node¥H¤Î©Ò¦³Äݩ󥦪º³]³Æ¡C·í¨Ï¥ÎªÌ®i¶}Node¡A¤U­±ªº¨Æ¥ó±N·|±Ò°Ê¡G

Private Sub tvwDir_Expand(ByVal node As ComctlLib.node)
    ' A Node is being expanded.
    Dim nd As Node
    ' Exit if the Node had already been expanded or has no children.
    If node.Children = 0 Or node.Children > 1 Then Exit Sub
    ' Also exit if it doesn't have a dummy child Node.
    If node.Child.text <> "***" Then Exit Sub
    ' Remove the dummy child item.
    tvwDir.Nodes.Remove node.Child.index
    ' Add all the subdirs of this Node object.
    AddSubdirs node
End Sub

TvwDir_Expandµ{§Ç¨Ï¥ÎNodeª«¥óªºChildrenÄÝ©Ê¡A§Y±N¥¦ªº¤lNodes¼Æ¥Ø¶Ç¦^¡A¦Ó¥BChildÄݩʶǦ^¥¦ªº²Ä¤@­Ó¤lNode¡CAddSubdirsµ{§Ç¼W¥[ÄÝ©ó¤@­Ó³Q«ü©wNodeªº¥þ³¡¤l¥Ø¿ý¡C¦]¬°¨C­ÓNodeªºKeyÄÝ©ÊÁ`¬O¾Ö¦³©MNode¬Û²Åªº¸ô®|¡A©Ò¥H¨ú±oScript.Folderª«¥ó©M­«½Æ¥¦ªºSubFolders¶°¦X¬O«Ü®e©öªº¡G

Private Sub AddSubdirs(ByVal node As ComctlLib.node)
    ' Add all the subdirectories under a Node.
    Dim fld As Scripting.Folder
    Dim nd As Node
    ' The path in the Node is held in its key property, so it's easy
    ' to cycle on all its subdirectories.
    For Each fld In FSO.GetFolder(node.Key).SubFolders
        Set nd = tvwDir.Nodes.Add(node, tvwChild, fld.Path, fld.Name, 3)
        nd.ExpandedImage = 4
        ' If this directory has subfolders, add a plus sign.
        If fld.SubFolders.Count Then AddDummyChild nd
    Next
End Sub

§Y¨Ï³oµ{¦¡½X¥u¯àŪ¨ú©M®i¥Ü¥Ø¿ý¾ð¡A±zÁÙ¬O¥i¥H²³æ¦a­×¥¿¥¦¥H¨Ï¥ÎTreeView±±¨î¶µ¨Ó³B²z¨ä¥L§ÎºAªº¸ê®Æ¡C

¦nªº¨Ï¥Î¤èªk¬O¥Î¶¥¼h¦¡ªº®æ¦¡¨ÓÂsÄý¸ê®Æ®w¡C¥H¨ì³B³£¦³ªºBiblio.MdbÁ|¨Ò¡G·í¨Ï¥ÎªÌ®i¶}Node®É¡A¥i¥HŪ¨ú©Ò¦³µo¦æªÌªº¦W¦r¦bTreeView±±¨î¶µ¤¤¦Ó¥BÅã²{¬ÛÃöªº¼ÐÃD¡C³o¼Ë·|¤ñ­«½ÆŪ¨ú©Ò¦³±±¨î¶µ¤¤ªº¸ê®Æ§Ö«Ü¦h¡A¦Ó¥B¬d¬Ý³o¨Ç°O¿ý·|¸û²M·¡¡C¦bÀH®Ñ¥úºÐ¤¤¤v¦³½d¨Òµ{¦¡¨Óªí²{³o­Ó§Þ¥©¡C

´M§äNodes¶°¦Xª«¥ó
¡@

·í»Ý­n±oª¾TreeView±±¨î¶µªº¸ê°T®É¡A¥²¶·´M§äNodes¶°¦X¡C¤j³¡¤Àªº¨Ò¤l¡A¤£¯à³æ¥u±q²Ä¤@­Ó¶µ¥Ø¤@ª½·j´M¨ì³Ì«á¤@­Ó¶µ¥Ø¡A¦]¬°³o¶¶§Ç¬°Nodes¥[¤Jªº¥ý«á¶¶§Ç¡A¹ï³o¨ÇNodes¦Ó¨¥¨ÃµL¥ô¦óÃöÁp¡C

­n«ö·Ó¦¸§ÇÀ˵øTreeView±±¨î¶µªº©Ò¦³¶µ¥Ø¡A¨C­ÓNodeª«¥ó»Ý¥]§tÃö©ó»P¨ä¥LNodes¦³¬Û¹ïÃö«YªºÄÝ©Ê¡C§Ú­Ì¤w¸g¬Ý¹LChildÄÝ©Ê¡A¨äÃöÁp¨ì²Ä¤@­Ó¤lNode¡A¦ÓChildrenÄݩʶǦ^¤lNodesªºÁ`¼Æ¡CNextÄÝ©Ê«h¶Ç¦^¦P¼Ë¼h¯Åªº¤U¤@­ÓNodeªº¬ÛÃö­È¡]¤U¤@­Ó¿ËÄÝNode¡^¡A¦ÓPreviousÄÝ©Ê«h¶Ç¦^¦P¼Ë¼h¯Å¤¤ªº«e¤@­ÓNodeªº¬ÛÃö­È¡]«e¤@­Ó¿ËÄÝNode¡^¡CFirstSibling©MLastSiblingÄݩʤÀ§O¶Ç¦^²Ä¤@­Ó©M³Ì«á¤@­ÓNodeªº¬ÛÃö­È¡A¥¦­Ì¦b¬Û¦Pªº¼h¯Å¡C³Ì«áParentÄݩʶǦ^Nodeªº¤W¼h¬ÛÃö­È¡A¦ÓRootÄݩʶǦ^Node©ÒÄݪº³Ì³»¶¥¯Å¡C¡]½Ð°O±o¡A¥i¥H¦³«Ü¦h­ÓRoot Nodes¡C¡^¥i¥H¨Ï¥Î³o¨ÇÄÝ©Ê¥h´ú¸Õ«ü©wªºNode¦b­þ­Ó¶¥¼h¡C³o¸Ì¦³¨Ç½d¨Ò¡G

' Check whether a Node has no children (two possible approaches).
If Node.Children = 0 Then MsgBox "Has no children"
If Node.Child Is Nothing Then MsgBox "Has no children"
' Check whether a Node is the first child of its parent (two approaches).
If Node.Previous Is Nothing Then MsgBox "First Child" 
If Node.FirstSibling Is Node Then MsgBox "First Child"
' Check whether a Node is the last child of its parent (two approaches).
If Node.Next Is Nothing Then MsgBox "Last Child" 
If Node.LastSibling Is Node Then MsgBox "Last Child"
' Check whether a Node is the root of its own tree (two approaches).
If Node.Parent Is Nothing Then MsgBox "Root Node" 
If Node.Root Is Node Then MsgBox "Root Node" 
' Get a reference to the first root Node in the control.
Set RootNode = TreeView1.Nodes(1).Root.FirstSibling

¤£­nÅå³Y¡A¤j¦h¼Æ¼g´M§äNodes¶°¦Xªº³£¬O¥Î»¼°jªº¤è¦¡¡C³q±`¡A±z¥H¤@­ÓNodeª«¥ó¬°¶}©l¡AÀò¨ú¥¦ªº²Ä¤@­Ó¤lNode¡AµM«á¥Î»¼°jªk¨Ó©I¥s¥¦ªº©Ò¦³¤UÄÝ¡C¤U­±ªº±Ô­z¬O³o­Ó¤èªkªº½d¨Ò¡C¥¦ªº¥Øªº¬O«Ø¥ß¤@­Ó¦r¦ê¥Nªí¤@­ÓTreeView±±¨î¶µ©Î¨ä¤¤¤§¤@­Ósubtreeªº¤º®e¦r¦ê¡C¦r¦ê¤¤ªº¨C¤@¦æ³£¥Nªí¤@­ÓNodeª«¥ó¡A©Î¬O³\¦h¤Ï¬M±_ª¬¼h¯Åªºtab¦r¤¸¡C³o­Ó¨Ò¤l·|¶Ç¦^¤@­Ó¦r¦ê¡A¤º®e¬°©Ò¦³Nodes©Î¥i¬Ý¨£ªº¶µ¥Ø¡]´«¨¥¤§¡A¨ä¤W¼h¬O®i¶}ªº¡^¡G

' Convert the contents of a TreeView control into a string.
' If a Node is provided, it only searches a subtree.
' If last argument is False or omitted, all items are included.
Function TreeViewToString(TV As TreeView, Optional StartNode As Node, _
    Optional OnlyVisible As Boolean) As String
    Dim nd As Node, childND As Node
    Dim res As String, i As Long
    Static Level As Integer
    
    ' Exit if there are no Nodes to search.
    If TV.Nodes.Count = 0 Then Exit Function
    ' If StartNode is omitted, start from the first root Node.
    If StartNode Is Nothing Then
        Set nd = TV.Nodes(1).Root.FirstSibling
    Else
        Set nd = StartNode
    End If
    ' Output the starting Node.
    res = String$(Level, vbTab) & nd.Text & vbCrLf
    ' Then call this routine recursively to output all child Nodes.
    ' If OnlyVisible = True, do this only if this Node is expanded.
    If nd.Children And (nd.Expanded Or OnlyVisible = False) Then
        Level = Level + 1
        Set childND = nd.Child
        For i = 1 To nd.Children
            res = res & TreeViewToString(TV, childND, OnlyVisible)
            Set childND = childND.Next
        Next
        Level = Level - 1
    End If
    ' If searching the whole tree, we must account for multiple roots.
    If StartNode Is Nothing Then
        Set nd = nd.Next
        Do Until nd Is Nothing
            res = res & TreeViewToString(TV, nd, OnlyVisible)
            Set nd = nd.Next
        Loop
    End If
    TreeViewToString = res
End Function

¹Ï10-9¬°¨Ï¥Î³o­Ó¨Ò¤lªº½d¨Òµ{¦¡©MŪ¨ú¡u°O¨Æ¥»¡v¤¤¦r¦êªº®ÄªG¡C±z¥i¥H¥Î«Ü¦h¤èªk¨Ó¬ü¤ÆTreeViewToStringªº¹Lµ{¡CÁ|¨Ò¨Ó»¡¡A¯à«Ø¥ß¤@­Ó¥Î¨Ó¦C¦LTreeView±±¨î¶µ¤º®eªºµ{¦¡¡]¥]¬A©Ò¦³ªº³sµ²½u¡BÂI°}¹Ïµ¥µ¥¡^¡C¨Ï¥ÎÃþ¦üªº¤èªk¡A¥i¥H¼g¤@­Ó¯àÀx¦s©MŪ¨úTreeView¹ê»Úª¬ªpªºµ{¦¡¡A¨ä¤¤¥]§t©Ò¦³Nodeª«¥óªºExpandedÄÝ©Ê¡C


¡@

¹Ï10-9 ¨Ï¥ÎTreeViewToStringªºµ{¦¡¡C

¹ê§@©ì¦²
¡@

¥t¤@­Ó±`¨£ªº¾Þ§@´N¬OTreeView±±¨î¶µªº©ì¦²¡A¬O¥Î¨Ó½Æ»s©Î²¾°Ê³¡¥÷¶¥¼h¡C©ì¦²ªº¹ê§@¨Ã«D·¥¬°®e©ö¡C­º¥ý¥²¶·¤F¸ÑNode©ì©Ô¹B§@ªº¶}©l»Pµ²§ô¡AµM«á±z­n½Æ»s©Î²¾°Ê³¡¥÷ªºNodes¶°¦X¡CÁÙ­n¹w¨¾¿ù»~ªº¾Þ§@¡A¦p·í¨Ï¥ÎÀÉ®×Á`ºÞ®É¡A¦pªG©ì©Ô¤@­Ó¥Ø¿ý¨ì¥¦ªº¤º¼h¥Ø¿ýªº¸Ü¡A´N¤£·|¹B§@¡C

TreeView±±¨î¶µ´£¨Ñ¤@¨ÇÄÝ©Ê©M¤èªk¨Ó°õ¦æ©ì¦²¥\¯à¡C±z¥i¥H¨Ï¥ÎHitTestªº¤èªk¨Ó±oª¾Nodeª«¥óªº«ü©w®y¼Ð¡]¤@¯ë¨Ó»¡¡A¨Ï¥ÎMouseDown¨Æ¥ó¨Ó¹ï·Ç­n©ì©ÔªºNode°_©l¦ì§}¡^¡C¨Ï¥ÎDropHighlightÄݩʨӬð¥X·Æ¹«©Ò«üªºNode¡A©Ò¥H±z¥i¥H´£¨Ñµ¹¨Ï¥ÎªÌ¥i¯à¥Ø¼ÐªºNode¹B§@¡C

¹Ï10-10´N¬O­ÓCD¤¤ªº½d¨Ò¡A¯à¸ÕÅç±qTreeView±±¨î¶µ©Î¦b¦P¼ËªºTreeView±±¨î¶µ¤¤¶i¦æ©ì¦²¡C®æ¦¡¤Wªº¨â­Ó±±¨î¶µÄÝ©ó¤@­Ó±±¨î¶µ°}¦C¡A©Ò¥H¬Û¦Pªºµ{¦¡½X¥i¦bµL½×¬Oµ{¦¡½X©Î¥Øªº±±¨î¶µ¹B§@¡C


¡@

¹Ï10-10 ¥i¨Ï¥Î©ì¦²¨Ó²¾°Ê©Î½Æ»s±±¨î¶µ¶¡©ÎªþÄÝ©ó¬Û¦PTreeView±±¨î¶µ¤¤ªº¤l¾ð¡C

¤@¯ë¦Ó¨¥¡A³o­Ó©ì©Ôªº°Ê§@¥HMouseDown¨Æ¥ó°µ±Ò°Ê¡G

' The source control
Dim SourceTreeView As TreeView
' The source Node object
Dim SourceNode As Node
' The state of Shift key during the drag-and-drop operation
Dim ShiftState As Integer

Private Sub TreeView1_MouseDown(Index As Integer, _
    Button As Integer, Shift As Integer, x As Single, y As Single)
    ' Check whether we are starting a drag operation.
    If Button <> 2 Then Exit Sub
    ' Set the Node being dragged, or exit if there is none.
    Set SourceNode = TreeView1(Index).HitTest(x, y)
    If SourceNode Is Nothing Then Exit Sub
    ' Save values for later.
    Set SourceTreeView = TreeView1(Index)
    ShiftState = Shift
    ' Start the drag operation.
    TreeView1(Index).OLEDrag
End Sub

OLEStartDrag¨Æ¥óµ{§Ç¨Ì¾aCtrlÁ䪺ª¬ºA¨Ó¨M©w²¾°Ê©Î½Æ»s¶µ¥Ø¡G

Private Sub TreeView1_OLEStartDrag(Index As Integer, _
    Data As MSComctlLib.DataObject, AllowedEffects As Long)
    ' Pass the Key property of the Node being dragged.
    ' (This value is not used; we can actually pass anything.)
    Data.SetData SourceNode.Key
    If ShiftState And vbCtrlMask Then
        AllowedEffects = vbDropEffectCopy
    Else
        AllowedEffects = vbDropEffectMove
    End If
End Sub

¦bOLEDragOver¨Æ¥óµ{§Ç¤¤¡A±z´£¨Ñ¨Ï¥ÎªÌ¦^õX(feedback)¡AÂǥѬð¥X·Æ¹««ü¦VªºNode¡C¡]µ{¦¡½X©M¥Øªº±±¨î¶µ·|¦P®Éµo¥Í¡C¡^

Private Sub TreeView1_OLEDragOver(Index As Integer, _
    Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, _
    Shift As Integer, x As Single, y As Single, State As Integer)
    ' Highlight the Node the mouse is over.
    Set TreeView1(Index).DropHighlight = TreeView1(Index).HitTest(x, y)
End Sub

³Ì«á¥²¶·¥h¼i¦æ¸sÅ餤³Ì¬°½ÆÂøªºOLEDragDrop¡C­º¥ý¥²¶·¤F¸Ñ·Æ¹«¬O§_²¾¨ì¥Ø¼Ð±±¨î¶µªºNode¡C¦pªG¬Oªº¸Ü¡ANodeªºµ{¦¡½X·|Åܦ¨¥Ø¼ÐNodeªº¤UÄÝ¡F¦pªG¤£¬O¡A«hµ{¦¡½X·|Åܦ¨¥Ø¼Ð±±¨î¶µ¤¤ªºRoot Node¡C¦pªGµ{¦¡©M¥Ø¼Ð±±¨î¶µ¦P®Éµo¥Í¡A¤]¥²¶·­n¾á«O¥Ø¼ÐNode¨Ã«D¬°Node­ì©lµ{¦¡ªº¤UÄÝ¡A¤£µM·|³´¤JµL­­´`Àô¡C

Private Sub TreeView1_OLEDragDrop(Index As Integer, _
    Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, _
    Shift As Integer, x As Single, y As Single)
    Dim dest As Node, nd As Node
    ' Get the target Node.
    Set dest = TreeView1(Index).DropHighlight
    
    If dest Is Nothing Then
        ' Add the Node as the root of the target TreeView.
        Set nd = TreeView1(Index).Nodes.Add(, , , SourceNode.Text, _
            SourceNode.Image)
    Else
        ' Check that the destination isn't a descendant of the source
        ' Node.
        If SourceTreeView Is TreeView1(Index) Then
            Set nd = dest
            Do
                If nd Is SourceNode Then
                    MsgBox "Unable to drag Nodes here", vbExclamation
                    Exit Sub
                End If
                Set nd = nd.Parent
            Loop Until nd Is Nothing
        End If
        Set nd = TreeView1(Index).Nodes.Add(dest.Index, tvwChild, , _ 
            SourceNode.Text, SourceNode.Image)
    End If
    nd.ExpandedImage = 2: nd.Expanded = True

    ' Copy the subtree from source to target control.
    CopySubTree SourceTreeView, SourceNode, TreeView1(Index), nd
    ' If this is a move operation, delete the source subtree.
    If Effect = vbDropEffectMove Then
        SourceTreeView.Nodes.Remove SourceNode.Index
    End If
    Set TreeView1(Index).DropHighlight = Nothing
End Sub

CopySubTree»¼°jµ{§Ç°õ¦æ¹ê»Úªº½Æ»s«ü¥O¡]¤@­Ó¥Ñ½Æ»s²Õ¦¨ªº²¾°Ê¦æ¬°·|¦ñÀHµÛ§R°£«ü¥O¡^¡C¥¦¤¹³\¤Þ¥Î¬ÛÃöªº­ì©l½X©M¥Ø¼ÐTreeView±±¨î¶µ¡A©Ò¥H¥i¥H®e©ö¦a¦b¨ä¥Lµ{¦¡¤¤¤ÏÂаõ¦æ¡C

Sub CopySubTree(SourceTV As TreeView, sourceND As Node, _
    DestTV As TreeView, destND As Node)
    ' Copy or move all children of a Node to another Node.
    Dim i As Long, so As Node, de As Node
    If sourceND.Children = 0 Then Exit Sub
    
    Set so = sourceND.Child
    For i = 1 To sourceND.Children
        ' Add a Node in the destination TreeView control.
        Set de = DestTV.Nodes.Add(destND, tvwChild, , so.Text, _
            so.Image, so.SelectedImage)
        de.ExpandedImage = so.ExpandedImage
        ' Now add all the children of this Node in a recursive manner.
        CopySubTree SourceTV, so, DestTV, de
        ' Get a reference to the next sibling.
        Set so = so.Next
    Next
End Sub

¤£»Ý­n»¼°jµ{§Ç¨Ó§R°£¤@­Ó¤l¾ð¡A¦]¬°¥u­n§R°£¤FNodeª«¥ó¡A¥¦ªº©Ò¦³¤UÄÝNodes¤]·|¦Û°Êªº§R°£¡C

ListView±±¨î¶µ
¡@

»PTreeView±±¨î¶µ¬Û¦P¡AListView±±¨î¶µ¤]ÀHµÛÀÉ®×Á`ºÞ¦Ó¬°¤H¼ôª¾¡C²{¦b³\¦hªºµøµ¡³nÅé¨Ï¥Î³oºØ¨Ã±Æªº±±¨î¶µ¡A¦Ó¥B¥¦­Ì³£³QºÙ¬°Ãþ¦üÀÉ®×Á`ºÞªºÀ³¥Îµ{¦¡¡C¦b³o¨ÇÀ³¥Îµ{¦¡¤¤¡A¨Ï¥ÎªÌ¿ï¾Ü¤F¤@­Ó¥ª¤èTreeView±±¨î¶µªºNode¡A±µµÛ±N·|¦b³Ì¥k¤èªºListView±±¨î¶µ¤¤¬Ý¨ì¨ä¬ÛÃö¸ê°T¡C

ListView±±¨î¶µ¤ä´©¥|­Ó°ò¥»À˵ø«ü¥O¡G¤j¹Ï¥Ü¡B¤p¹Ï¥Ü¡B²M³æ©M¸Ô²Ó¸ê®Æ¡C¬°¤F¸Ñ¨C¤@­Ó¼Ò¦¡¦p¦óÅã¥Ü¡A¸Õ¸ÕÀÉ®×Á`ºÞ¤¤ªºÀ˵ø¿ï³æ¸Ìªº¬ÛÃö¶µ¥Ø¡]¸Ô²Ó¸ê®Æ¼Ò¦¡´£¨Ñ·¥¸ÔºÉªº¿ï³æ«ü¥O¡^¡C¬°¤F©ú¥Õ³o¨Ç±±¨î¶µªºÆF¬¡©Ê¡A±zÀ³¸Ó¤F¸ÑWindows®à­±¥i¬Ý¦¨¬O­Ó¨Ï¥Î¤j¹Ï¥Ü¼Ò¦¡ªºListView±±¨î¶µ¡A¥B¹Ï¥Üªº­I´º¬°³z©úªº¡C·í¿ï¾Ü¸Ô²Ó¸ê®Æ®É¡AListView±±¨î¶µ¦p¦Pªí®æªº±±¨î¶µ¡A¦Ó¥B¸û¦³²Õ´ªºÅã¥Ü©Ò¦³¶µ¥Øªº¸ê°T¡C

Visual Basic 6ªºListView±±¨î¶µ¦³³\¦h·s¯S©Ê¡G¥¦¥i¥H¦b¦æ¼ÐÃD©ÎÀx¦s®æ¨ÓÅã¥Ü¹Ï¥Ü¡F¥¦¤ä´©¦Û°Ê°lÂÜ¡B¾ã¦C¿ï¨ú©M¤¹³\¸ê®Æ¦æ­«·s±Æ¦C¡F¦Ó¥B¥¦ªº¶µ¥Ø¾Ö¦³¿W¥ßªºBold©MColor°Ñ¼Æ¡C·sªºListView±±¨î¶µ¯à°÷Åã¥Ü­I´º¹Ï¡B®æ½u»P®Ö¿ï¤è¶ô¡C

ListView±±¨î¶µ©µ¦ù¥X¨â­Ó¤£¦Pªº¶°¦X¡GListItems¶°¦X¥]§t¿W¥ßªºListItemª«¥ó¡A¨C¤@­Ó³£¸ò±±¨î¶µ¤¤ªº¶µ¥Ø¦³Ãö¡FColumnHeaders¶°¦X¥]§t¦b¸Ô²Ó¸ê®Æ¼Ò¦¡¤¤»P¼ÐÃD¦³Ãö«YªºColumnHeadersª«¥ó¡C²Ä¤T­Ó¶°¦X¡AListSubItems¡A¥]§t©Ò¦³¦b¸Ô²Ó¼Ò¦¡¤¤ªº¤è®æ¸ê°T¡C


¡@

³]©w³]­p¶¥¬qÄÝ©Ê
¡@

·í±z¨Ï¥ÎÄݩʵøµ¡¥h«Ø¥ßListView±±¨î¶µ¤¤¤j³¡¤ÀªºÄݩʮɡA¨Ï¥ÎListView±±¨î¶µªºÄÝ©Ê­¶¥h³]©w·|§ó¦n¡A½Ð¬Ý¹Ï10-11©Ò¥Ü¡C


¡@

¹Ï10-11 ListView±±¨î¶µÄÝ©Ê­¶ªº¤@¯ë­¶ÅÒ¡C

¤@¯ë©ÊÄÝ©Ê
¡@

¥ý«e¤w¸g´£¨ì¹LViewÄݩʤF¡A¥¦¥i¥H¬O¤U¦C°Ñ¼Æ¤¤ªº¤@­Ó¡G0-lvwIcon¡B1-lvwSmallIcon¡B2-lvwList©Î¬O3-lvwReport¡C¥i¦b°õ¦æªº®É­Ô§ïÅÜ¥¦ªºÄÝ©Ê©MÅý¨Ï¥ÎªÌ¨Ó§ïÅÜ¡]¤@¯ëÂǥѴ£¨Ñ¥|­Ó¿ï¶µ¦bÀ³¥Îµ{¦¡¤¤ªºView¿ï³æ¡^¡CArrangeÄݩʨM©w¬O§_¹Ï¥Ü­n¦Û°Ê¹ï»ô¡G¾a¥ª¹ï»ô¡]1-lvwAutoLeft¡^¡B¾a¤W¹ï»ô¡]2-lvwAutoTop¡^¡B©Î¤£¹ï»ô¡]0-lvwNone¡A¹w³]­È¡^¡C¥u¦³¦b¤j¹Ï¥Ü»P¤p¹Ï¥Ü¼Ò¦¡¦¹Äݩʤ~¦³®Ä¥Î¡C

LabelEditÄݩʨM©w¨Ï¥ÎªÌ¬O§_¯à½s¿èÃö©ó±±¨î¶µ¤¤ªº¶µ¥Ø¤å¥ó¡C¦pªG³o­ÓÄݩʳ]¬°0-lvwAutomatic¡A«h½s¿èªº°Ê§@¥u¦³¥ÎStartLabelEditªº¤èªk¤~¯à±Ò°Ê¡C¦ÓLabelWrap¥¬ªLÄÝ©Ê©ú½T¦a«ü¥X¦b¤j¹Ï¥Ü¼Ò¦¡¤U¸ûªøªº¤å¦r¼ÐÅÒ·|¦Û°Ê´«¦æ¡CHideColumnHeaders¥¬ªLÄݩʨM©w¦b¸Ô²Ó¸ê®Æ¼Ò¦¡¤¤ªº¦æ¼ÐÃD¬O§_Åã¥Ü¡C¡]¹w³]­È¬OFlase¡A·|Åý¦æÅã¥Ü¡C¡^¦pªGMultiSelectÄݩʬ°¯u¡A«hListView±±¨î¶µ±N¦p¦PListBox±±¨î¶µ¡A¨äMultiSelectÄݩʬ°2-Extended¡C

Visual Basic 6¦³¤@¨Ç·sªºÄÝ©Ê¡C¦pªG³]AllowColumnReorder¬°True¡A«h¦b¸Ô²Ó¸ê®Æ¼Ò¦¡¤U¡A¨Ï¥ÎªÌ¥i©ì²¾¼ÐÃD¨Ó­«·s±Æ³]¸ê®Æ¦æ¡CÁÙ¥i¥H±NGridLines³]¬°True¨Ó§ïÅÜListView±±¨î¶µªºÅã¥Ü¡]·|¼W¥[¤ô¥­©M««ª½ªº®æ½u¡^¡C²Ä¤T­Ó·sªºÄÝ©Ê¡AFlatScrollBar¡A¯à§ïÅÜListView±±¨î¶µ¬O§_Åã¥Ü¡A¤£¹L¥¦¦ü¥G¦³ÂI°ÝÃD¡G¦pªG³]¥¦¬°True¡A«h±²°Ê¶b±N¤£·|Åã¥Ü¡CListView±±¨î¶µ»PTreeView±±¨î¶µ¦³³¡¥÷·sÄݩʬO¬Û¦Pªº¡C¤§«eµ§ªÌ±Ô­z¹LCheckBoxesÄÝ©Ê¡]¥i¥HÅã¥Ü¨C­Ó¶µ¥Øªº¿ï¨ú¤è¶ô¡^©MFullRowSelectÄÝ©Ê¡]¿ï¨ú¾ã¦C¨Ó¥N´À¤@¦C¤¤²Ä¤@­Ó¶µ¥Ø¡^¡C¦ÓHotTracking¥¬ªLÄݩʦpªG¬°True¡A«h¨Ï¥ÎªÌ±N·Æ¹«²¾¨ì¬Y­Ó¶µ¥Ø¤§¤W®É«K¯à§ïÅÜÅã¥Ü±¡ªp¡CHoverSelection¥¬ªLÄݩʦpªG¬°True¡A«h¥u­n¨Ï¥ÎªÌ²¾°Ê·Æ¹«¨ì¶µ¥Øªº¤W¤è¡A´N¯à°÷¿ï¨ú¸Ó¶µ¥Ø¡C¬Ý¬Ý¹Ï10-12ªº¨Ò¤l¡A´N¯à¤F¸Ñ³o¨Ç·sªºÄÝ©Ê¡C


¡@

¹Ï10-12 ListView±±¨î¶µ·s¯S©Êªº¦Cªí¡G¿ï¨ú¤è¶ô¡B®æ½u¡B©M¨C­Ó¶µ¥ØªºBold¥H¤ÎForeColorÄÝ©Ê¡C¦C»P¦CªºÅܤƬO¥Î¿j¥Ë­I´º¹Ï¨Ó§e²{¡C

¥i±N¤T­Ó»²§UListView±±¨î¶µªºImageList°µ³o¼ËªºÁp·Q¡G²Ä¤@­ÓImageList¦b¤j¹Ï¥Üªº®É­Ô¨Ï¥Î¡A²Ä¤G­Ó«h¥i¥H¦b¥ô¦ó¼Ò¦¡¤¤¨Ï¥Î¡A¦Ó²Ä¤T­Ó«h¥Î¦b¦æ¼ÐÃDªº¹Ï¥Ü¡C¥i¦b³]­p¶¥¬q¥HÄÝ©Ê­¶ªº¼v¹³®w­¶ÅÒ¨Ó³]©w³o¨Ç¬ÛÃöªºImageList±±¨î¶µ¡A©Î¬O¦b°õ¦æ®É±NListViewªºIcons¡BSmallIcons©MColumnHeaderIconsÄݩʤÀ§O³]©w¬°¬Û¹ïªºImageList±±¨î¶µ¡C

ColumnHeadersÄݩʬOVisual Basic 6´£¨Ñªº·sÄÝ©Ê¡A¦]¬°¥ý«eªºListViewª©¥»¨S¦³´£¨Ñ¦æ¼ÐÃDªº¥\¯à¡G

' You can use the same ImageList control for different properties.
Set ListView1.Icons = ImageList1
Set ListView1.SmallIcons = ImageList2
Set ListView1.ColumnHeaderIcons = ImageList2

¥i¥H¤Ä¿ïÄݩʹï¸Ü¤è¶ô¤¤ªº±Æ§Ç­¶ÅÒªº¤@¨ÇÄݩʨÓÅýListView±±¨î¶µªº¶µ¥Ø¦Û°Ê±Æ§Ç¡C¦pªG·Q­n±Æ§Ç¶µ¥Ø¡A´N­n±NSortedÄݩʳ]¬°True¡CSortKey«h¬O·Q­n³Q±Æ§Çªº¦æªº¯Á¤Þ¡]²Ä¤@¦æ¬°0¡^¡A¦ÓSortOrder«h¬O±Æ§Çªº¶¶§Ç¡]0-lvwAscending©Î1-lvwDescending¡^¡A±z¥i¥H¦b°õ¦æ®É½Õ¾ã³o¨ÇÄÝ©Ê¡C

¸ê®Æ¦æ¦æ­º
¡@

³]­p¶¥¬q®É¡A¥i«Ø¥ß¤@­Ó©Î¦h­ÓColumnHeaderª«¥ó¡A¥u­n¥ÎÄݩʹï¸Ü¤è¶ôªº¸ê®Æ¦æ¦æ­º­¶ÅÒ¡C¥u»Ý«ö¤@¤U´¡¤J¸ê®Æ¦æ«ö¶s¡AµM«á¿é¤JTextÄݩʪº­È¡]¥Î¨ÓÅã¥Ü¼ÐÃD¡^¡AAlignmentÄÝ©Ê¡]¥ª¡B¥k©Î¤¤¥¡¡AÁöµM²Ä¤@­Ó¦æ¼ÐÃD¥u¯à¾a¥ª¹ï»ô¡^¡A©MWidth¡]³æ¦ì¬°twip¡^¡C¤]¥i¥H«ü©wµ¹Key©MTagÄݩʤ@­Ó­È¡AµM«á³]¸m¼ÐÃD»Ý­n¥Î¨ìªº¹Ï¥Üªº¯Á¤Þ­È¡C¡]³o¬OÃö©óImageList±±¨î¶µªºColumnHeaderIconsÄݩʪº¯Á¤Þ­È¡A¦Ó¦pªG¦æ¼ÐÃD¨S¦³¥ô¦ó¹Ï¥Üªº¸Ü´N¬°0¡C¡^

­I´º¹Ï¹³
¡@

Visual Basic 6ªºListView±±¨î¶µ¤ä´©­I´º¹Ï¡C·Q­nŪ¨ú¤@±i¹Ï¤ù¨ì±±¨î¶µ¤¤¡A¥u­n¦b³]­p®É¿ï¨ú¦ì©óÄݩʹï¸Ü¤è¶ô¸Ìªº¹Ï¤ù­¶Åҳ̥ª¤èªºPictureÄÝ©Ê¡C¥i¸ü¤J¬°PictureBox±±¨î¶µ©Ò¤ä´©ªº¹ÏÀɮ榡¡C¥t¥~¦³¨â­Óªþ¥[ªºÄݩʸò­I´º¹Ï¹³¦p¦óÅã¥Ü¦³Ãö¡A¦ý¥u¯à¦b¤@¯ëÄݩʵøµ¡¤¤°µ½Õ¾ã¡CPictureAlignmentÄÝ©ÊÅý±z½Õ¾ã¹Ï¤ù¦b±±¨î¶µ¥|­Ó¨¤¸¨¤§¤@ªº¦ì¸m¡A¤¤¥¡¡A©ÎªÌÂX±i¬°¾ã­Ó±±¨î¶µ¤j¤p¡CTextBackground«h¬O½Õ¾ãListViewªº¶µ¥Ø­I´º¹Ï¹³ªº³z©ú¡]¹w³]­È¬°0lvwTransparent¡^»P§_¡]1-lvwOpaque¡^¡F«áªÌ¥u¦³¦b²£¥ÍListItemª«¥ó®É¤~·|Åã²{¡C

­I´º¹Ï¹³¥i¥H¥æ´À­I´º¦âªº¤èªk¨ÓÅã¥Ü¡A¦p¹Ï10-12©Ò¥Ü¡C¦Ó©Ò­n°µªº´N¬O«Ø¥ß¤@­Ó¨â¦æ°ªªºÂI°}¹Ï¡AµM«á³]PictureAlignment­È¬°5-lvwTile©MTextBackground­È¬°0-lvwTransparent¡C

°õ¦æ¶¥¬qªº¹B§@
¡@

¦b³]­p¶¥¬q¶È¯à©w¸qListView±±¨î¶µªº¥~»ª¡A­Y­n¶ñ¤J¸ê®Æ«h¶·¸g¥Ñµ{¦¡½X¡C¦b³o¸Ì¡Aµ§ªÌ±N·|»¡©ú¦p¦ó¼W¥[©M±±¨î³o­Ó±±¨î¶µªº¸ê®Æ¡C

¼W¥[ListItemª«¥ó
¡@

ÂÇ¥ÑListItems¶°¦XªºAdd¤èªk¥i¼W¥[·sªº¶µ¥Ø¨ìListView±±¨î¶µ¤¤¡A»yªk¦p¤U¡G

Add([Index], [Key], [Text], [Icon], [SmallIcon]) As ListItem

Index¬O·s¶µ¥Øªº¦ì¸m¡]¦pªG©¿²¤Index¡A¸Ó¶µ¥Ø±N·|¼W¥[¦b¾ã­Ó¶°¦Xªº¥½ºÝ¡^¡CKey¬OListItems¶°¦X¤¤·s´¡¤J¶µ¥ØªºÃB¥~¯Á¤ÞÁä¡AText¬°Åã¥Üªº¦r¦ê¡AIcon«h¬OImageList±±¨î¶µ¤¤ªí¥Ü¤j¹Ï¥Üªº¤@­Ó¯Á¤Þ©Î¯Á¤ÞÁä¡A¦ÓSmallIcon¬O¤p¹Ï¥Üªº¯Á¤Þ©Î¯Á¤ÞÁä¡C©Ò¦³ªº°Ñ¼Æ³£¬O¥i¿ï¾Üªº¡C

Add¤èªk·|¶Ç¦^©Ò«Ø¥ßªºListItemª«¥ó¡A¥i¥H¥Î¦¹¨Ó³]©w¤@¨Ç¤£·|¶Ç°eµ¹Add¤èªkªºÄÝ©Ê¡A¥H¤U´N¬O­Ó¨Ò¤l¡G

' Create a new item with a "ghosted" appearance.
Dim li As ListItem
Set li = ListView1.ListItems.Add(, , "First item", 1)
li.Ghosted = True

ListItemª«¥ó¤ä´©¤@¨Ç·sªºÄÝ©Ê¡CBold©MForeColorÄݩʱ±¨îª«¥óªº²ÊÅé©MÃC¦â¡CToolTipTextÄݩʯà©w¸q¨C­Ó¶µ¥Ø¤£¦Pªº´£¥Ü¦r¦ê¡A¦ÓCheckedÄÝ©Ê¥i³]©w©Î¶Ç¦^¶µ¥Ø¿ï¨ú¤è¶ôªºª¬ºA¡]¦pªGListViewªºCheckBoxesÄݩʬ°Trueªº¸Ü¡^¡C·í»Ý­n³]©w¦h­ÓÄݩʮɡA¥i¨Ï¥ÎWithÃöÁä¦r¦ñÀHµÛAdd¤èªk¡G

With ListView1.ListItems.Add(, , "John Ross", 1)
    .Bold = True
    .ForeColor = vbRed
    .ToolTipText = "Manager of the Sales Dept."
End With

·íListView±±¨î¶µªºMultiSelectÄݩʬ°True®É¡A¨Ï¥ÎªÌ¥i¥H«ö¦íCtrl©ÎShiftÁä¨Ó¿ï¨ú¦h­Ó¶µ¥Ø¡C¸g¥Ñ¦bµ{¦¡½X¤¤½Õ¾ãSelected¬°¾A·í­È´N¯à­×§ïListItemª«¥óªº¿ï¨úª¬ºA¡C¤£¹L¹ï©ó³oÃþªºListView±±¨î¶µ¦Ó¨¥¡AÁÙ¥²¶·³]©wSelectedItemÄݩʨϤ§¦¨¬°²{¦æªºListItem¶µ¥Ø¡G

' Make the first ListItem object the current one.
Set ListView1.SelectedItem = ListView1.ListItems(1)
' Select it.
ListView1.ListItems(1).Selected = True

¼W¥[ColumnHeaderª«¥ó
¡@

¦³®É¦b³]­p¶¥¬q¨Ã¤£ª¾¹D­þ¨ÇListView±±¨î¶µªº¸ê®Æ¦æ¸ÓÅã²{¡CÁ|¨Ò¨Ó»¡¡A¥i¯à­nÅã¥Ü¨Ï¥ÎªÌ¦Û©w¬d¸ßªºµ²ªG¡A¦¹®É¨Ã¤£ª¾¹DÄæ¦ìªº¼Æ¶q»P¦WºÙ¡C¦b³oºØ±¡ªp¤U¡A»Ý­n¦b°õ¦æ®É¥HColumnHeaders¶°¦X¤¤ªºAdd¤èªk¨Ó«Ø¥ßColumnHeaderª«¥ó¡A»yªk¦p¤U¡G

Add([Index], [Key], [Text], [Width], [Alignment], [Icon]) _
    As ColumnHeader

Index¬O¦b¶°¦Xªº¦ì¸m¡AKey¬OÃB¥~ªº¯Á¤ÞÁä¡AText¬OÅã¥Ü¦b¼ÐÃDªº¦r¦ê¡A¦ÓWidth«h¬O³æ¦ì¬°twipsªº¦æ¼e¡CAlignment¬°¤U¦C­È¨ä¤¤¤§¤@¡G0-lvwColumnLeft¡B1-lvwColumnRight©Î2-lvwColumnCenter¡CIcon¬O°Ñ¦Ò¦ÛColumnHeaderIconsÄݩʪºListImage±±¨î¶µ¤º¹Ï¤ùªº¯Á¤Þ©Î¯Á¤ÞÁä¡CTagÄݩʬO°ß¤@¥i¦bColumnHeaderª«¥ó«Ø¥ß«á½Õ¾ãªºÄÝ©Ê¡A©Ò¥H³q±`¥i¥H©ñ±óAdd¤èªk¶Ç¦^ªº­È¡C

' Clear any existing column header.
ListView1.ColumnHeaders.Clear
' The alignment for the first column header must be lvwColumnLeft.
ListView1.ColumnHeaders.Add , , "Last Name", 2000, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "First Name", 2000, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Salary", 1500, lvwColumnRight

¼W¥[ListSubItems
¡@

¨C¤@­ÓListItemª«¥ó¥]§t¤@­ÓListSubItems¶°¦X¡A¯à«Ø¥ß»P¥D­nListItemª«¥ó¤¤¦ì©ó¬Û¦P¦CªºÅã¥Ü­È¡]·í±±¨î¶µ¦b¸Ô²Ó¸ê®Æ¼Ò¦¡¤U®É¡^¡C³o­Ó¶°¦X¨ú¥Nª©±±¨î¶µªºSubItems°}¦C¡]¬°¤F¬Û®e©Ê¡A¸Ó°}¦C¤´µM¤ä´©¡^¡C¥i¥H¨Ï¥ÎListSubItems¶°¦X¤¤ªºAdd¤èªk¨Ó«Ø¥ß·sªºListSubItemª«¥ó¡G

Add([Index], [Key], [Text], [ReportIcon], [ToolTipText]) _
    As ListSubItem

Index¬O¶°¦X¤¤·s¶µ¥Øªº¦ì¸m¡AKey¬OÃB¥~ªº¯Á¤ÞÁä¡AText¬OÅã¥Ü¦b¤è®æ¤¤ªº¦r¦ê¡AReportIcon¬O°Ñ¦Ò¦ÛSmallIconsÄݩʪºImageList±±¨î¶µ¤º¹Ï¤ùªº¯Á¤Þ©Î¯Á¤ÞÁä¡C¤]¥i¥H½Õ¾ã¨C¤@­ÓListSubItemªºBold©MForeColor°Ñ¼Æ¡G

' This ListItem goes under ColumnHeader(1).
With ListView1.ListItems.Add(, , "Ross", 1)
    .Bold = True
    ' This ListSubItem goes under ColumnHeader(2).
    With .ListSubItems.Add(, , "John")
        .Bold = True
    End With
    ' This ListSubItem goes under ColumnHeader(3).
    With .ListSubItems.Add(, , "80,000")
        .Bold = True
        .ForeColor = vbRed
    End With
End With

ListSubItemª«¥ó¥u¦³¦bListView±±¨î¶µ¬°¸Ô²Ó¸ê®Æ¼Ò¦¡©M¦³¨¬°÷ªºColumnHeaderª«¥ó®É¤~·|¯u¥¿ªºÅã¥Ü¡CÁ|­Ó¨Ò¤l¡A¦pªGColumnHeaders¶°¦X¥u¥]§t¤T­Ó¤¸¯À¡AListView±±¨î¶µ±N¥u·|Åã¥Ü¤T­Ó¶µ¥Ø¦b¨C¤@¦æ¤¤¡C¦]¬°³Ì¥ª¤èªºColumnHeaderª«¥ó¦ì¦bListItem¤¸¯À¤W¡A¦]¦¹¥u¦³ListSubItems¶°¦Xªº«e¨â­Ó¤¸¯À¤~·|Åã²{¡C

ListSubItemª«¥ó¤]¤ä´©TagÄÝ©Ê¡A¦p¦¹¯à¥Î¨ÓÀx¦s¸ò¸ê®Æ¶µ¦³Ãöªºªþ¥[¸ê°T¡C

±q¸ê®Æ®w¤¤¸ü¤J¸ê®Æ
¡@

ListView±±¨î¶µ¤£·|¦Û°Ê¦a»PRemoteDate©ÎADO¸ê®Æ±±¨î¶µ¶i¦æ¸ê®Æ³sµ²¡C´«¥y¸Ü»¡¡A¦pªG·Q­nŪ¨ú¸ê®Æ®w¤¤ªº¸ê®Æ¨ì±±¨î¶µªº¸Ü¡A¥²¶·¤â°Ê¶i¦æ¡CŪ¨ú¸ê®Æ¨ìListView±±¨î¶µ¤¤¦bÆ[©À¤W¨Ã¤£§xÃø¡A¦ý¥²¶·ª`·N¨Ç²Ó¸`¡C­º¥ý»Ý¨ú±oRecordsetªºÄæ¦ì²M³æ©M«Ø¥ß¬Û¹ïÀ³¥B¦X¾A¼e«×ªºColumnHeaderª«¥ó¡CÁÙ¦³¥²¶·©ñ±ó¤£¯à¦bListView±±¨î¶µ¤¤Åã¥ÜªºÄæ¦ì¡]¨Ò¦pBLOBÃþªº¡^¡A¥B¥²¶·¨M©w¨C­ÓÄæ¦ì³Ì¨Îªº¦ì¸m¡]¼Æ¦r©M¤é´Á¶·¾a¥k¡A¨ä¥L«h¾a¥ª¡^¡C¤U¦Cµ{¦¡»¡©ú³o¨Ç¥Îªk¡A¥i¦b±zªºµ{¦¡¤¤¨Ï¥Î¦¹¤èªk¡A¦p¤U¡G

Sub LoadListViewFromRecordset(LV As ListView, rs As ADODB.Recordset, _
    Optional MaxRecords As Long)
    Dim fld As ADODB.Field, alignment As Integer
    Dim recCount As Long, i As Long, fldName As String
    Dim li As ListItem
    
    ' Clear the contents of the ListView control.
    LV.ListItems.Clear
    LV.ColumnHeaders.Clear
    ' Create the ColumnHeader collection.
    For Each fld In rs.Fields
        ' Filter out undesired field types.
        Select Case fld.Type
            Case adBoolean, adCurrency, adDate, adDecimal, adDouble 
                alignment = lvwColumnRight
            Case adInteger, adNumeric, adSingle, adSmallInt, adVarNumeric
                alignment = lvwColumnRight
            Case adBSTR, adChar, adVarChar, adVariant
                alignment = lvwColumnLeft
            Case Else
                alignment = -1      ' This means "Unsupported field type". 
        End Select
        ' If field type is OK, create a column with the correct alignment.
        If alignment <> -1 Then
            ' The first column must be left-aligned.
            If LV.ColumnHeaders.Count = 0 Then alignment = lvwColumnLeft
            LV.ColumnHeaders.Add , , fld.Name, fld.DefinedSize * 200, _
                alignment
        End If
    Next
    ' Exit if there are no fields that can be shown.
    If LV.ColumnHeaders.Count = 0 Then Exit Sub

    ' Add all the records in the recordset.
    rs.MoveFirst
    Do Until rs.EOF
        recCount = recCount + 1
        ' Add the main ListItem object.
        fldName = LV.ColumnHeaders(1).Text
        Set li = LV.ListItems.Add(, , rs.Fields(fldName) & "")
        ' Add all subsequent ListSubItem objects.
        For i = 2 To LV.ColumnHeaders.Count
            fldName = LV.ColumnHeaders(i)
            li.ListSubItems.Add , , rs.Fields(fldName) & ""
        Next
        If recCount = MaxRecords Then Exit Do
        rs.MoveNext
    Loop
End Sub

LoadListViewFromRecordset¨ç¦¡»Ý­n¤@­ÓADO Recordset©M¿ï¾Ü©ÊªºMaxRecords°Ñ¼Æ¡A¨ä¥Î¨Ó­­¨î°O¿ýÅã¥Üªº¼Æ¶q¡C³o¬O¥²»Ýªº¡A¦]¬°—¬Û¹ï©óbound±±¨î¶µ¡A¥u»Ý¸ü¤J¯u¥¿­nÅã¥Üªº¸ê°T—¦¹¨ç¦¡·|Ū¨úRecordsetªº©Ò¦³¸ê®Æ¦C¡A³o¥i¯à·|¬O·¥¬°¤¾ªøªº¹Lµ{¡C«Øij³]©wMaxRecords¬°100©Î200¡A¬Û«H³o¼Ë·|´£¤É³sµ²¸ê®Æ®wªº®É¶¡©MCPUªº®Ä²v¡C

¥t¤@­Ó°ÝÃD¬O±q¸ê®Æ®w¤¤Åª¨ú¸ê®Æ®É¡A¥i¯à»Ý­n¤â°Ê½Õ¾ã¨C¤@­Ó¦æ¼e¡CLoadListViewFromRecordset·|¨Ï©Ò¦³ColumnHeaderª«¥ó¨Ï¥Î¸ÓÄæ¦ì³Ì¤jªº¼e«×¡A¦ý¬O¦b¤j³¡¤Àªº±¡ªp¤U¡A¦s¦b¸ê®Æ®w¤¤ªº­È·|¤ñ¸Ó­Èµu«Ü¦h¡C¬°¤FÁקKÅý¨Ï¥ÎªÌ¶i¦æÁcº¾ªº½Õ¾ã¼e«×µ{§Ç¡A¥i¥Î¤U­zªº¤èªk¨Ó§ïÅÜ©Ò¦³ªº¦æ¼e¡G

Sub ListViewAdjustColumnWidth(LV As ListView, _
    Optional AccountForHeaders As Boolean)
    Dim row As Long, col As Long
    Dim width As Single, maxWidth As Single
    Dim saveFont As StdFont, saveScaleMode As Integer, cellText As String
    ' Exit if there aren't any items.
    If LV.ListItems.Count = 0 Then Exit Sub
    
    ' Save the font used by the parent form, and enforce ListView's
    ' font. (We need this in order to use the form's TextWidth
    ' method.)
    Set saveFont = LV.Parent.Font
    Set LV.Parent.Font = LV.Font
    ' Enforce ScaleMode = vbTwips for the parent.
    saveScaleMode = LV.Parent.ScaleMode
    LV.Parent.ScaleMode = vbTwips
    
    For col = 1 To LV.ColumnHeaders.Count
        maxWidth = 0
        If AccountForHeaders Then
            maxWidth = LV.Parent.TextWidth(LV.ColumnHeaders(col).Text)+200
        End If
        For row = 1 To LV.ListItems.Count
            ' Retrieve the text string from ListItems or ListSubItems.
            If col = 1 Then
                cellText = LV.ListItems(row).Text
            Else
                cellText = LV.ListItems(row).ListSubItems(col - 1).Text
            End If
            ' Calculate its width, and account for margins.
            ' Note: doesn't account for multiple-line text fields.
            width = LV.Parent.TextWidth(cellText) + 200
            ' Update maxWidth if we've found a larger string.
            If width > maxWidth Then maxWidth = width
        Next
        ' Change the column's width.
        LV.ColumnHeaders(col).width = maxWidth
    Next
    ' Restore parent form's properties.
    Set LV.Parent.Font = saveFont
    LV.Parent.ScaleMode = saveScaleMode
End Sub

¬°¤F½T©w¨C­Óµ¹©w¦æ©ÒÀx¦s­Èªº³Ì¨ÎÄæ¼e¡AListViewAdjustColumnWidth¨ç¦¡¨D¥X©Ò¦³Àx¦s¦b¦æ¤º¦r¦êªº³Ì¤j¼e«×¡C°ÝÃD¬O¥Ñ©óListView¤£¤ä´©TextWidth¤èªk¡A©Ò¥H³o­Óµ{§Ç¨Ì¾a±±¨î¶µ©ÒÄݪí³æªºTextWidth¤èªk¡C¦pªG¥HTrue­È§@¬°²Ä¤G­Ó°Ñ¼Æ¡A¦¹µ{§Ç¤]·|­pºâ©Ò¦³ColumnHeaderª«¥óªºTextÄÝ©Ê¡A©Ò¥H¼ÐÃD¤]¤£·|³QºI±¼¡C

ListView±±¨î¶µ¤w¯à°÷¦Û°Ê¦a½Õ¾ã¾A¦Xªº¤j¤p¡A§Y¨ÏVisual Basic ActiveX±±¨î¶µ©|¥¼´£¨Ñ³o­Ó¥\¯à¡C¨Æ¹ê¤W¡A±z¯à½Õ¾ã¦¨¸Ó¶µ¥Ø³Ì¤jªº¤º®e¡A³sÄò¦b¦æ¼ÐÃDªºÃä½t«ö¨â¤U¡]¦p¦P¦bÀÉ®×Á`ºÞªº¸Ô²Ó¸ê®Æ¼Ò¦¡¤W¡^¡C¦bÀH®Ñ¥úºÐ¤¤ªº½d¨Ò¡A±z±Nµo²{¥t¤@­ÓListViewAdjustColumnWidthª©¥»¡A¨Ï¥ÎAPI©I¥s¥N´À­ì©lªºVisdual Basicµ{¦¡½X¨Ó½Õ¸`¤j¤p¡C¤U­zªºµ{¦¡½d¨Ò±N®i¥Ü¦p¦ó¨Ï¥ÎListViewAdjustColumnWidth¨ÓÅã¥ÜNorthWind.Mdb¤¤©Ò¦³¦bOrders¸ê®Æªíªº©Ò¦³°O¿ý¡A¦p¹Ï10-13©Ò¥Ü¡G

Private Sub Form_Load()
    Dim cn As New ADODB.Connection, rs As New ADODB.Recordset
    ' WARNING: you might need to modify the DB path in the next line.
    cn.Open "Provider=Microsoft.Jet.OLEDB.3.51;" _
        & "Data Source=C:\VisStudio\VB98\NWind.mdb"
    rs.Open "Orders", cn, adOpenForwardOnly, adLockReadOnly
    LoadListViewFromRecordset ListView1, rs
    ListViewAdjustColumnWidth ListView1, True
End Sub

¦bµ§ªÌªº233-MHz¾÷¾¹¤¤¡A³o¬qµ{¦¡ªá¤F15¬í¤~§¹¦¨¡A¤j³¡¤À¨Ï¥ÎªÌ®£©È¨S³o¼Ëªº­@¤ß¡C¦]¦¹¡AÀ³¸Ó©ú´¼¦a¨Ï¥Î¦¹§Þ³N¥B³]©w¤@­ÓŪ¨ú¸ê®Æ®w¼Æ¥Øªº¤W­­¡C


¡@

¹Ï10-13 ³o­Ó½d¨Ò·|Ū¨úNorthWindªºOrders¸ê®Æªí¨ìListView±±¨î¶µ¡A¦Ó¥B·íÂI¿ï¦æ¼ÐÃD®É·|¦Û°Ê±Æ§Ç¨ä¦æ¤§¸ê®Æ¡C

¸ê®Æ¦æªº±Æ§Ç¥H¤Î­«·s±Æ¦C
¡@

¤§«e¤w¤¶²Ð¹L¦b³]­p¶¥¬q¦p¦ó¨Ó©w¸q±Æ§ÇÁä­È©M±Æ§Ç¶¶§Ç¡C©ó°õ¦æ®É¥i½Õ¾ãSorted¡BSortKey©MSortOrderÄݩʨӹF¨ì¦P¼Ëªº®ÄªG¡C³q±`·í¨Ï¥ÎªÌ«ö¤U¦æ¼ÐÃD®É¤~°µ³o¥ó¨Æ¡A¦¹°Ê§@·|¤ÞµoColumnClick¨Æ¥ó¡G

Private Sub ListView1_ColumnClick(ByVal ColumnHeader As _
    MSComctlLib.ColumnHeader)
    ListView1.SortKey = ColumnHeader.Index - 1
    ListView1.Sorted = True
End Sub

¦pªG·Q­n¥H¦¹ºØ¤èªk¨Ó´£¨Ñ¤£¦P¤è¦Vªº±Æ§Ç¯à¤O®É¡A·|µy·L½ÆÂø¨Ç¡G²Ä¤@¦¸ÂI¿ï·|¾É­P¤É¾­ªº±Æ§Ç¥\¯à¡A²Ä¤G¦¸ÂI¿ï«h·|¾É­P­°¾­±Æ§Ç¡C·Q¹F¨ì¦¹§@¥Î¡A¥²¶·Àˬd³QÂI¿ïªº¦æ¬O§_¤w±Æ§Ç¡G

Private Sub ListView1_ColumnClick(ByVal ColumnHeader As _
    MSComctlLib.ColumnHeader)
    ' Sort according to data in this column.
    If ListView1.Sorted And _
        ColumnHeader.Index - 1 = ListView1.SortKey Then
        ' Already sorted on this column, just invert the sort order.
        ListView1.SortOrder = 1 - ListView1.SortOrder
    Else
        ListView1.SortOrder = lvwAscending
        ListView1.SortKey = ColumnHeader.Index - 1
    End If
    ListView1.Sorted = True
End Sub

ListView±±¨î¶µ¥u¯à±Æ§Ç¦r¦ê¸ê®Æ¡C¦pªG·Q­n°w¹ï¼Æ¦r©Î¤é´Á°µ±Æ§Ç¡A¥²¶·¥Î¨Ç§Þ¥©¡C«Ø¥ß¤@­Ó·sªºColumnHeaderª«¥ó¡A¥H¦r¦ê¨Ó¶ñ¤J¡A¦Ó¦¹¦r¦ê¨Ó¦Û·Q­n±Æ§Çªº¼Æ¦r©Î¤é´Á¡A±µµÛ±Æ§Ç¸Ó¦æ¡A³Ì«á§R°£¨º¨Ç¶µ¥Ø¡C³o¸Ì¦³­Ó¨ç¦¡¥i¹F¦¨¦¹®ÄªG¡G

Sub ListViewSortOnNonStringField(LV As ListView, ByVal ColumnIndex As _
    Integer, SortOrder As Integer, Optional IsDateValue As Boolean)
    Dim li As ListItem, number As Double, newIndex As Integer
    ' This speeds up things by a factor of 10 or more.
    LV.Visible = False
    LV.Sorted = False
    ' Create a new, hidden field.
    LV.ColumnHeaders.Add , , "dummy column", 1
    newIndex = LV.ColumnHeaders.Count - 1
        
    For Each li In LV.ListItems
        ' Extract a number from the field.
        If IsDateValue Then
            number = DateValue(li.ListSubItems(ColumnIndex - 1))
        Else
            number = CDbl(li.ListSubItems(ColumnIndex - 1))
        End If
        ' Add a string that can be sorted using the Sorted property.
        li.ListSubItems.Add , , Format$(number, "000000000000000.000")
    Next
    ' Sort on this hidden field.
    LV.SortKey = newIndex
    LV.SortOrder = SortOrder
    LV.Sorted = True
    ' Remove data from the hidden column.
    LV.ColumnHeaders.Remove newIndex + 1
    For Each li In LV.ListItems
        li.ListSubItems.Remove newIndex
    Next
    LV.Visible = True
End Sub

¦p¥ý«e©Ò»¡ªº¡A¥i¨Ï¥Î¦bColumnClick¨Æ¥óµ{§ÇªºListViewSortOnNonStringField¨ç¦¡¡C¤W­zªºµ{¦¡µLªk³B²z­t¼Æ¡A¦ýÀH®Ñ¥úºÐ¤¤ªº§¹¾ãµ{¦¡¤w¸g¸Ñ¨M¤F³o­Ó°ÝÃD¡C


¤p¯µ³Z

·íSortedÄݩʬ°True®É¡A´¡¤J©Î²¾°£°Ê§@»Ý­n«Ü¤[ªº®É¶¡¡C·í­n§ó·s¸ê®Æ®É¡A¥i¥ý±NSortedÄݩʳ]¬°False¡A§¹¦¨«á¦A­«³]¬°True¡CµøListView±±¨î¶µ¶µ¥Øªº¦h¹è¡A¥i»´©ö¦a´£¤ÉÃe¤jµ{¦¡ªº°õ¦æ³t«×¡C


¸ê®Æ¦æ¥i¦b°õ¦æ®É²¾°Ê©Î­«±Æ¡C±NAllowColumnReorderÄݩʳ]¬°True´N¯àÅý¨Ï¥ÎªÌ©ì¦²¸ê®Æ¦æ¨ì·sªº¦ì¸m¡CµM¦Ó¡A·íListView±±¨î¶µªºCheckBoxesÄݩʬ°True®É¤£¸Ó¦p¦¹°µ¡C¦pªG¨Ï¥ÎªÌ²¾°Ê²Ä¤@¦æ¡A«h±±¨î¶µªº¤º®e±N·|Åܱo¤£¤@¼Ë¡A¦]¬°¿ï¨ú¤è¶ô·|ÀHµÛ²Ä¤@¦æ¦Ó²¾°Ê¡C

±qµ{¦¡½X¤¤¨Ó±±¨î­þ¤@¦æ­n²¾°Ê¥B²¾°Ê¨ì­þ¨à·|¤ñ¸û¦n¡C¦b³oºØ±¡§Î¤U¡A¥u»Ý«ü©w·s­Èµ¹ColumnHeaderª«¥óªºPositionÄÝ©Ê¡C¨Ò¦p¡A¥i¥H¥æ´«¤U¦Cµ{¦¡«e¨â¦æªº¦ì¸m¡G

ListView1.ColumnHeaders(1).Position = ListView1.ColumnHeaders(1).Position _
    + 1
' You need to refresh after reordering one or more columns.
ListView1.Refresh

·j´M¶µ¥Ø
¡@

¥i¥ÎFindItemªk§Ö³t¦a·j´MListView±±¨î¶µ¤¤ªº¦r¦ê¡A»yªk¦p¤U¡G

FindItem(Search, [Where], [Start], [Match]) As ListItem

Search°Ñ¼Æ¬°­n·j¯Áªº¦r¦ê¡CWhere°Ñ¼Æªí¥Ü­þÃþ¦r¦ê­n³Q·j´M¡G0-lvwText°w¹ïListItemª«¥óªºTextÄÝ©Ê¡F1-lvwSubItem°w¹ïListSubItemªºTextÄÝ©Ê¡F¦Ó2-lvwTag«h°w¹ïListItemª«¥óªºTagÄÝ©Ê¡CStart°Ñ¼Æ¬°­n±q­þ­Ó¯Á¤Þ©Î¯Á¤ÞÁ䪺ListItemª«¥ó¶}©l·j´M°_¡CMatch¥i¥H¬O0-lvwWholeWord©Î1-lvwPartial¡A¨ä©w¸q¬O§_­n§¹¥þ²Å¦X©Î³¡¥÷²Å¦X¡C¡]Match¥u¯à¥Î¦bWhere­È¬°0-lvwText®É¡C¡^

­nª`·Nªº¬OµLªk¦bListSubItemª«¥óªºTagÄÝ©Ê·j´M¡A¤]¤£¯à­­¨î·j´MListItemsªº³æ¤@¦æ¡C©Ò¦³ªº·j´M¦æ¬°³£¬O¤À¤j¤p¼gªº¡C

¨ä¥LªºÄÝ©Ê¡B¤èªk¡B¨Æ¥ó
¡@

ListView±±¨î¶µ©Ò¤ä´©ªºÄÝ©Ê¡B¤èªk©M¨Æ¥ó»PTreeView±±¨î¶µªº¹p¦P¡A©Ò¥H¦b³o¸Ì´N¤£¦A°µ¸Ô²Óªº¤¶²Ð¡C

¥iÂÇ¥ÑBeforeLabelEdit©MAfterLabelEdit¨Æ¥ó¡A±±¨î¨Ï¥ÎªÌ¦ó®É½s¿è±±¨î¶µªº­È¡CµL½×¨Ï¥ÎªÌ«ö¤U¦Cªº¦ó³B¡A¥u¦³¦ì³B³Ì¥ª¤è¸ê®Æ¦æªº¶µ¥Ø·|³Q½s¿è¡C¦pªG·Q­n¥Îµ{¦¡¨Ó¶}©l½s¿è¦æ¬°¡A¥²¶·¥ýÅý¬Y­ÓListItemª«¥ó¦¨¬°³Q¿ï¨úªº¶µ¥Ø¡AµM«á°õ¦æStartLabelEdit¤èªk¡G

ListView1.SetFocus
Set ListView1.SelectedItem = ListView1.ListItems(1)
ListView1.StartLabelEdit

¦pªG±±¨î¶µªºCheckBoxesÄݩʳ]¬°True¡A¨º»ò¥iÂÇ¥ÑListItemª«¥óªºCheckedÄݩʨÓŪ¨ú©M­×§ï¨C¦Cªº®Ö¨úª¬ºA¡C¥i¦bItemCheck¨Æ¥óµ{§Ç¤W¼¶¼gµ{¦¡¨Ó®·®»ÂI¿ï®Ö¨ú¤è¶ôªº°Ê§@¡C¬Û¦ü¦a¡A·íListItemª«¥ó³QÂI¿ï®É¡A«h·|¤ÞµoItemClick¨Æ¥ó¡C

ListItemª«¥óÁÙ¥]§tEnsureVisible¤èªk¡A¦pªG»Ý­nªº¸Ü¡A¨ä¥i±²°Ê±±¨î¶µªº¤º®e¦Ó²¾°Ê¬Y¶µ¥Ø¨ì¥i¨£ªº±±¨î¶µ°Ï°ì¡C¥i¥H¬d¸ßListViewªºGetFirstVisible¤èªk¡A¨ä·|¶Ç¦^²Ä¤@­Ó¥i¨£ªºListItemª«¥óªº¤Þ¥Î¡C

ListViewªºHitTest¤èªk·|¶Ç¦^ListItemª«¥óªº¸Ô²Ó®y¼Ð¡C¤@¯ë·|¦b©ì¦²°Ê§@¤¤¨Ï¥Î¦¹¤èªk¡A¨Ã·f°tDropHighlightÄÝ©Ê¡A³o¨Ç¦b»¡©úTreeView±±¨î¶µ¤w»¡©ú¡C¤£¹L¡A¦b¸Ô²Ó¸ê®Æ¼Ò¦¡¤U®É¡A¨Ã¨S¦³Â²³æªº¤èªk¥i¨M©w·Æ¹«ÂI¦b­þ­Ó¸ê®Æ¦æ¡C

Toolbar±±¨î¶µ
¡@

¤j¦h¼ÆªºWindowsÀ³¥Îµ{¦¡³£¦³¤@­Ó¥H¤Wªº¤u¨ã¦C¡A´£¨Ñ¨Ï¥ÎªÌ¥Î·Æ¹«ÂI¿ï¨Ó°õ¦æ¤j³¡¤À±`¥Îªº«ü¥O¡C¤u¨ã¦C¤£¦Ü©ó¨ú¥N¿ï³æ¡A°ß¤@ªº²z¥Ñ¬O¡G¿ï³æ¥i¥H¥ÑÁä½L¨Ó°õ¦æ¡F¤u§@¦C¤£¦æªº²z¥Ñ¬O¡A¤£¹L¥¦­Ì¤@©w·|Åýµ{¦¡§ó¹ê¥Î¥B§ó¬üÆ[¡C

Visual BasicªºToolbar±±¨î¶µ¯à¥]§t«ö¶s©M¨ä¥Lªº±±¨î¶µ¡A¥B¥iÅý¨Ï¥ÎªÌ¦Û­q¡CVisual Basic 6¼W¥[¤F¥­­±¼Ë¦¡ªº¤u¨ã¦C¡A¨ä¦]¬°Microsoft Internet Explorer¦Ó¼s¬°¤Hª¾¡A¥B¨ä¤º«Ø¤U©Ô¦¡¿ï³æ¡C

Toolbar±±¨î¶µ¦³­ÓButtons¶°¦X¡A¥]§tButtonª«¥ó¡C¨C­ÓButtonª«¥ó¥i¥H¬O­Ó«ö¶s¡B¤À¹j°Ï¡B©Î¤@­Ó¹w³Æµ¹¨ä¥L±±¨î¶µ©ñ¸mªº¦ì¸m¡]¤@¯ë¬OTextBox©MComboBox±±¨î¶µ¡^¡C¦¹¥~¡AButtonª«¥ó¥]§tButtonsMenus¶°¦X¡A¨C­ÓButtonMenuª«¥ó¬Ò¬O­Ó¤U©Ô¦¡¿ï³æ¶µ¥Ø¡C¡]¦pªGButtonª«¥ó¤£¬O¤U©Ô¦¡¿ï³æ¡A«h¸Ó¶°¦X¬OªÅªº¡C¡^


¡@

³]©w³]­p¶¥¬qÄÝ©Ê
¡@

¤j³¡¤Àªº±¡ªp¤U¡A·|©ó³]­p®É©w¸qToolbarªº¥~Æ[¡AµM«á¹ïÀ³¨Ï¥ÎªÌ¹ï«ö¶sªºÂI¿ï¡C³]­p®É¦³¨âºØ¹B§@Toolbarªº¤èªk¡G¨Ï¥ÎToolbarºëÆF©Î¤â°Ê³]©w¨äÄÝ©Ê¡C³o¨â­Ó¤èªk¨Ã«D¤¬¬Û±Æ¥¸ªº¡G¨Æ¹ê¤Wµ´¤j³¡¥÷ªº®É­Ô¡A·|¥ý³z¹LºëÆF¨Ó«Ø¥ßªì©lªºToolbar±±¨î¶µ¡AµM«á©ó¨äÄÝ©Ê­¶¦A¥[¥H·L½Õ·|§ó¤è«K¡C

ToolbarºëÆF
¡@

ToolbarºëÆF¬OVisual Basic 6·sªº¼W¯q¶°¥\¯à¡A¦ý¦b¼W¯q¶°ºÞ²z¹ï¸Ü¤è¶ô¤ºªº²M³æ¨Ã¨S¦³¦¹ºëÆF¡C¨ä¹ê¬O¥²¶·¦w¸ËÀ³¥Îµ{¦¡ºëÆF¡G§¹¦¨«á¡A±z·|¦b¼W¯q¶°¿ï³æ¤¤µo²{¤u¨ã¦CºëÆF¡C¦pªG¿ï¾Ü¤F¸Ó«ü¥O¡AºëÆF·|¼W¥[¤@­Ó·sªºToolbar±±¨î¶µ©ó²{¦æªí³æ¤W¡A¨Ã¥iÅý±z¦Û­q¥¦¡C¤]¥i¥H¤â°Ê©ñ¸mToolbar¤u¨ã¦C©óªí³æ¤W¡AµM«áºëÆF·|¦Û°Ê±Ò°Ê¡C

ToolbarºëÆFªº¨Ï¥Î·¥¬°Â²³æ¡C¦b¥ª¤èªº¤è¶ô¤¤·|¦³¤@±Æ«ö¶s¡]¨£¹Ï10-14¡^¡A¨ä¥iÅý±z¿ï¨ú­n¥[¨ìToolbar±±¨î¶µªº«ö¶s¡C¥i¦b¨â­Ó¤è¶ô¶¡²¾°Ê¶µ¥Ø»P§ïÅܨä¦b¤u¨ã¦Cªº¶¶§Ç¡A¤èªk¬°³z¹L¤¤¶¡ªº«ö¶s©Î¥Î©ì¦²ªº¤è¦¡¡C¦¹ºëÆF¦P®É¤]·|«Ø¥ß¹ïÀ³ªºImageList±±¨î¶µ¡C·í§¹¦¨¤u¨ã¦C«á¡A·|¥X²{¹ï¸Ü¤è¶ô¸ß°Ý¬O§_­nÀx¦s¦¨rwpÀÉ¡A¸ÓÀɯàÅý±z¦b©¹«á¥[³t«Ø¥ßÃþ¦üªº¤u¨ã¦C¡C


¡@

¹Ï10-14¥ÎToolbarºëÆF«Ø¥ß¤@­Ó¤u¨ã¦C¡C

¤@¯ë©ÊªºÄÝ©Ê
¡@

¦b«Ø¥ß¤u¨ã¦C«á¡A©ó¨ä¤W«ö¤U·Æ¹«¥kÁä¨Ã¿ï¾Ü ÄÝ©Ê ¿ï³æ¥i¶}±Ò¨ä ÄÝ©Ê­¶ ¡C ÄÝ©Ê­¶ ªº ¤@¯ë ­¶ÅÒ¤¤¥]§t¤j³¡¤À³]­p¶¥¬q¥ÎªºÄÝ©Ê¡A¯à±±¨îToolbar±±¨î¶µ¸û¨Îªº¥~Æ[©M¦æ¬°¡A¦p¹Ï10-15©M¹Ï10-16©Ò¥Ü¡CÁ|¨Ò¨Ó»¡¡A­n°µ¤U¦Cªº¨M©w¡G¨Ï¥ÎªÌ¬O§_¥i©ó°õ¦æ®É¦Û­q¤u¨ã¦C¡]AllowCustomizeÄÝ©Ê¡^¡A·íªí³æ¤j¤pÅܤƮɡA¤u¨ã¦C¬O§_­n¦Û°Ê´«¦æ¡]WrappableÄÝ©Ê¡^¡A¬O§_­nÅã¥ÜToolTips¡]ShowTipsÄÝ©Ê¡^¡A©M«ö¶sªº¹w³]¤j¤p¬°¦ó¡]ButtonWidth©MButtonHeightÄÝ©Ê¡^¡C­Y¦³»Ý­nªº¸Ü¡A«ö¶s·|¦Û°Ê¦aÂX®i¥H²Å¦X¨ä¼ÐÃD©Î¹Ï¤ù¡A©Ò¥H¤j³¡¤Àªº±¡ªp¤U¡A¨Ã¤£»Ý­n¥h­×§ï«á¨â­ÓÄݩʪº¹w³]­È¡C

Visual Basic 6¦³¤@¨Ç¦³½ìªº·sÄÝ©Ê¡A±z¥i¥H«Ø¥ß¥­­±¦¡¤u¨ã¦C¡A¥u­n±NStyleÄݩʳ]¬°1-tbrFlat¡A¥B¥i¨Ï¥ÎTextAlignmentÄݩʨӧïÅÜ«ö¶s¤W¼ÐÃD¬Û¹ï©ó¹Ï¤ùªº¹ï»ô¤è¦¡¡]0-tbrTextAlignBottom©Î1-tbrTextAlignRight¡^¡C

¤u¨ã¦C¤Wªº«ö¶s¥i¥H¦³¤TºØª¬ºA¡G¥¿±`¡BµL®Ä©Î¿ï¨úªº¡C¡]¦pªGStyle¬O1-tbrFlatªº¸Ü¡A·í·Æ¹«²¾¹L¬Y«ö¶s®É¡A¡u¿ï¨ú¡vª¬ºA´N·|µo¥Í¡^¡CToolbar±±¨î¶µ¨Ã«D¥Î¤T­ÓÄݩʨӫü¦V¦P¤@­ÓImageList±±¨î¶µ¤ºªº¤£¦P¹Ï¤ù¡A¦Ó¬O¥Î¥t¤@ºØ¤èªk¡G¨C­Ó«ö¶s¥u¥]§t¤@­ÓImageÄÝ©Ê¡Ð¥Nªí¯Á¤Þ©Î¯Á¤ÞÁä¡Ð¦Ó¥Ñ«ö¶sªºª¬ºAªí¥Ü­n¥Î­þ­ÓImageList±±¨î¶µ¡C¥i¦b³]­p©Î°õ¦æ®É¡A«ü©w¤T­ÓImageList±±¨î¶µµ¹ImageList¡BDisabledImageList©MHotImageListÄÝ©Ê¡CÁ|­Ó¨Ò¤l¡A¥i¨Ï¥Î¤@²Õ¶Â¥Õ¹Ï¥Üµ¹¥¿±`ª¬ºA»P¤@²Õ¦³ÃC¦âªº¹Ï¥Üµ¹¿ï¾Üª¬ºA¡A¨Ó¼Ò¥éInternet Explorer 4¡C¦pªG¤£­n«ü©w«á¨â­ÓÄÝ©Ê¡A«hToolbar·|¦Û°Ê«Ø¥ß¾A¦Xªº¹Ï¤ùµ¹µL®Ä©Î¿ï¨úª¬ºA¡C


¡@

¹Ï10-15 Toolbar±±¨î¶µÄÝ©Ê­¶ªº¤@¯ë­¶ÅÒ¡C


¡@

¹Ï10-16 Toolbar±±¨î¶µÄÝ©Ê­¶ªº«ö¶s­¶ÅÒ¡C

Buttonª«¥ó
¡@

¨S¦³«ö¶sªºToolbar±±¨î¶µ¬O¨S¥Îªº¡C±z¥i¥H¥ÎToolbarºëÆF¨Ó¼W¥[Buttonª«¥ó¡A¦p¥ý«e©Ò?­zªº¡A©Î¦bÄÝ©Ê­¶ªº«ö¶s­¶ÅÒ¤¤³]©w¡A¦p¹Ï10-16¡C¨C­Ó«ö¶s³£¦³­ÓCaptionÄÝ©Ê¡]¦pªG¥u­nÅã¥Ü¹Ï¥Ü¡A´N¤£­n¿é¤J¥ô¦ó¦r¦ê¡^¡A¤@­Ó«D¥²­nªº¦Û­q±Ô­z¡BTagÄÝ©Ê¡AButton¶°¦Xªº¯Á¤ÞÁä¡]«D¥²­nªº¡A¦ý¥i¥Î¥¦¨Ó§ïµ½µ{¦¡ªº¥iŪ©Ê¡^¡A­YToolbarªºShowTipsÄݩʬ°True®É¤~·|Åã¥ÜªºToolTipText¡A¥H¤Î¤@­ÓImage¯Á¤Þ©Î¯Á¤ÞÁä¡A«ü¦V¬ÛÃöªºImageList±±¨î¶µ¡C

Style¬OButtonª«¥ó¤¤³Ì·P¤H¿³½ìªºÄÝ©Ê¡C¦¹ÄݩʨM©wButtonªº¥~Æ[»P¦æ¬°¡A¥i¥H¬O¤U¦C­È¤§¤@¡G0-tbrDefault¡]¤@¯ë«ö¶s¡A´N¹³¥i«ö¤Uªº«ö¶s¡^¡B1-tbrCheck¡]«ö¤F¤§«á·|¤@ª½«O«ù«ö¦íªº±¡§Îªº«ö¶s¡A¦pCheckBox±±¨î¶µ¡^¡B2-tbrButtonGroup¡]¦³³\¦hÄÝ©ó¦P¤@­Ó¸s²Õªº«ö¶s¡A¦ý¬O¥u¯à¿ï¾Ü¤@­Ó¡A¦pOptionButton±±¨î¶µ¡^¡B3-tbrSeparator¡]¹j¶}©T©wªº¼e«×¡^¡B4-tbrPlaceholder¡]¥ÑWidthÄݩʨӱ±¨î¤À¹j°Ï°ìªº¤j¤p¡F³q±`¥Î¨Ó«Ø¥ß¤@­Ó¥iµ¹¨ä¥L±±¨î¶µ©ñ¸mªºªÅ¶¡¡^©Î5-tbrDropDown¡]¦³¤U©Ô½bÀYªº«ö¶s¡AÃþ¦ü¤U©Ô¦¡¿ï³æ¡^¡C

·íStyleÄݩʭȳ]¬°5-tbrDropDown®É¡A¥i¥H¼W¥[¤@­Ó¥H¤WªºButtonMenuª«¥óµ¹¸Ó«ö¶s¡C¡]µL½×«ö¶sªºStyle¬°¦ó³£¥i«Ø¥ßButtonMenu¶µ¥Ø¡A¦ý¥u¦³³]¬°tbrDropDownªº¤~¬Ý±o¨£¡^¡C¨C­ÓButtonMenuª«¥ó³£¦³­ÓTextÄÝ©Ê¡]¿ï³æ¼ÐÃD¡^¡BButtonMenus¶°¦X¤¤«D¥²­nªºKey»PTagÄÝ©Ê¡C¤£©¯¦a¡AButtonMenuª«¥óµLªkµ²¦X¹Ï¤ù¡G¤U©Ô¦¡¿ï³æ¥u¯à¥H¯Â¤å¦rÅã¥Ü¡A«Ü©úÅã¦a»PToolbar·Pı¤j¤£¬Û¦P¡C¨£¹Ï10-17ªº¨Ò¤l¡AToolbar±±¨î¶µªº²Ä¤@­Ó«ö¶s´N¬O­Ó¤U©Ô¦¡¿ï³æ¡C


¡@

¹Ï10-17 ¦³¤U©Ô¦¡¿ï³æªº¤u¨ã¦C¡C

°õ¦æ¶¥¬qªº¹B§@
¡@

¤@¥¹©óªí³æ¤W¼W¥[¤F¤@­ÓToolbar±±¨î¶µ«á¡A¥²¶·®·®»¨Ï¥ÎªÌ¹ï¥¦©Ò°µªº°Ê§@¡C¥i¯à»Ý­n©ó°õ¦æ®ÉÂǥѵ{¦¡¨Ó«Ø¥ß±±¨î¶µ¡A©ÎÅý¨Ï¥ÎªÌ¦Û­q¤§¡A¨Ã±N·sªºª©­±¦s°_¨Óµ¹«áÄòªº¹B§@¡C

«Ø¥ßButton©MButtonMenuª«¥ó
¡@

¥i¦b°õ¦æ¶¥¬q¥HButton¶°¦X¤¤ªºAdd¤èªk¨Ó«Ø¥ß·sButtonª«¥ó¡A»yªk¦p¤U¡G

Add([Index], [Key], [Caption], [Style], [Image]) As Button

Index¬O­n³Q¥[¨ì¶°¦X¤ºButtonª«¥óªº¦ì¸m¡AKey«h¬°¨ä«D¥²­n©Êªº¦r¦ê¯Á¤ÞÁä¡ACaption¬OÅã¥Ü¦b¤u¨ã¦C¤Wªº¤å¦r¡AStyle¨M©w¸Ó«ö¶s¬O¦óºØ§ÎºA¡]0-tbrNormal, 1-tbrCheck¡B2tbrButtonGroup¡B3-tbrSeparator¡B4-tbrPlaceholder©Î5-tbrDropDown¡^¡A¦ÓImage«h¬°¦b¤T­ÓImageList±±¨î¶µ¤º¹Ï¤ùªº¯Á¤Þ©Î¯Á¤ÞÁä¡C

·í«Ø§¹«ö¶sª«¥ó«á¡AÁٻݭn¥h³]©w¨ÇÃB¥~ÄÝ©Ê¡A¦pWidth¡]¹ï¹w³ÆªÅ¶¡ªº«ö¶s¦Ó¨¥¡^©MToolTipText¡CStyle¬°tbrCheck©ÎtbrButtonGroupªº«ö¶s¥i±N¨äValueÄݩʳ]¬°1-tbrPressed¡A§Y¥iÅý«ö¶s¦¨¬°³Q«ö¤Uªºª¬ºA¡C³o¸Ì¦³­Ó¼W¥[«ö¶sªº½d¨Òµ{¦¡¡G

' A button that can be in an on or off state
Dim btn As Button
Set btn = Toolbar1.Buttons.Add(, , , tbrCheck, "Lock")
btn.Value = tbrPressed
' A separator
Toolbar1.Buttons.Add, , , tbrSeparator
' Two buttons that are mutually exclusive
Set btn = Toolbar1.Buttons.Add(, , , tbrButtonGroup, "Green")
Set btn = Toolbar1.Buttons.Add(, , , tbrButtonGroup, "Red")
btn.Value = tbrPressed

·Q­n©ñ¸m¥ô¦ó±±¨î¶µ¦b¤u¨ã¦C¤W¡A¥i¥ý«Ø¥ßStyleÄݩʳ]¬°tbrPlaceholderªºButtonª«¥ó¡AµM«á²¾°Ê¸Ó±±¨î¶µ¨ì¾A·í¦ì¸m¡C¨Ò¦p¡A­n±NcboFontSizes±±¨î¶µ©ñ¦b¤u¨ã¦C¤W¡G

' Create a placeholder of proper width.
Dim btn As Button
Set btn = Toolbar1.Buttons.Add(, , , tbrPlaceholder)
btn.Width = cboFontSizes.Width
' Move the ComboBox control over the placeholder button.
Set cboFontSizes.Container = Toolbar1
cboFontSizes.Move btn.Left, btn.Top

¦pªG«Ø¥ßStyleÄݩʬ°tbrDropDownªº«ö¶s¡A«h¥i¥Î¨äButtonMenus¶°¦XªºAdd¤èªk¼W¥[¤@­Ó¥H¤Wªº¶µ¥Ø¨ì¶°¦X¤º¡G

Add ([Index], [Key], [Text]) As ButtonMenu

Indexªí¥Ü¦b¶°¦X¤¤ªº¦ì¸m¡AKey¬°«D¥²­nªº¯Á¤ÞÁä¡A¦ÓText«h¬O¿ï³æ¶µ¥Øªº¼ÐÃD¡C¤U­±µ{¦¡§Y¼W¥[¤@­Ó¦³¤T­Ó¿ï¶µªº¤U©Ô¦¡Buttonª«¥ó¡C

Dim btn As Button
Set btn = Toolbar1.Buttons.Add(, , , tbrDropDown, "New")
With btn.ButtonMenus
    .Add , , "File"
    .Add , , "Document"
    .Add , , "Image"
End With

¤ÏÀ³¨Ï¥ÎªÌªº°Ê§@
¡@

·í¨Ï¥ÎªÌÂI¿ï«ö¶s®É¡AToolbar±±¨î¶µ·|¤ÞµoButtonClick¨Æ¥ó¡A¦¹®É°õ¦æªºµ{¦¡À³¬°¡G

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComCtlLib.Button)
    Select Case Button.Key
        Case "New"
            Call mnuFileNew_Click
        Case "Save"
            Call mnuFileSave_Click
        ' And so on.
    End Select
End Sub

Visual Basic 6¤Þ¶i¤F¨â­Ó·s¨Æ¥ó¡A¨â­Ó³£¸ò¤U©Ô¦¡¿ï³æ¦³ÃöÁp¡C·í¨Ï¥ÎªÌ¶}±Ò¤U©Ô¦¡¿ï³æ®É·|¤ÞµoButtonDropDown¨Æ¥ó¡C¥i¥H¨Ï¥Î¦¹¨Æ¥ó¨Ó«Ø¥ß©Î­×§ï§@¥Î¤¤¿ï³æ¡Ð¨Ò¦p¡A³]©w­Ó§OButtonMenu¶µ¥ØªºVisible©ÎEnabledÄݩʩμW¥[·sªº¿ï³æ¶µ¥Ø¡G

Private Sub Toolbar1_ButtonDropDown(ByVal Button As MSComctlLib.Button)
    ' Make the "Open | Image" command unavailable if necessary.
    If Button.Caption = "Open" Then
        Button.ButtonMenus("Image").Enabled = ImagesAreEnabled
    End If
End Sub

·í¨Ï¥ÎªÌ¿ï¾Ü¤U©Ô¦¡¿ï³æªº«ü¥O«á·|¤ÞµoButtonMenuClick¨Æ¥ó¡G

Private Sub Toolbar1_ButtonMenuClick(ByVal ButtonMenu As 
    MSComctlLib.ButtonMenu)
    Select Case ButtonMenu.Key
        Case "Document"
            Call mnuFileNewDocument
        Case "Image"
            Call mnuFileNewImage
    End Select
End Sub

¦Û­qToolbar±±¨î¶µ
¡@

±z¥iÅý¨Ï¥ÎªÌ¦Û­qToolbar±±¨î¶µ¡C¦³¨â­Ó¤èªk¥i¥H¹F¨ì³o­Ó¥Øªº¡G³]AllowCustomizationÄݩʬ°True¥H«KÅý¨Ï¥ÎªÌ¦b¤u¨ã¦C¤W³s«ö¨â¤U·Æ¹«¶i¤J¦Û­q¼Ò¦¡¡A©ÎÂǥѵ{¦¡°õ¦æToolbarªºCustomize¤èªk¨Ó¶i¤J¦Û­q¼Ò¦¡¡C­Y¥u­n´£¨Ñ¦¹¯à¤Oµ¹¦³­­ªº¨Ï¥ÎªÌ®É¡A´N¥²¶·±Ä¥Î¤U­±ªº¤èªk¤F¡G

Private Sub Toolbar1_DblClick()
    If UserIsAdministrator Then Toolbar1.Customize
End Sub

µL½×¿ï¾Ü­þ­Ó¤èªk¡A³Ì«á³£·|Ãö³¬¦Û­q¤u¨ã¦C¹ï¸Ü¤è¶ô¡A¦p¹Ï10-18©Ò¥Ü¡C


¡@

¹Ï10-18¦Û­q¤u¨ã¦C¹ï¸Ü¤è¶ô¡C

·í¨Ï¥ÎªÌÃö³¬¦¹¹ï¸Ü¤è¶ô®É¡AToolbar±±¨î¶µ·|¤ÞµoChange¨Æ¥ó¡C¡]¤p¤ß¡G§Y¨Ï¨Ï¥ÎªÌ¨S¦³§ïÅܤu¨ã¦Cªºª©­±®É¡A¤´·|¤Þµo¦¹¨Æ¥ó¡^¡C¦b¦¹¨Æ¥ó³B²zµ{§Ç¤¤¡AÀ³­n°õ¦æSaveToolbar¤èªk¡A¨ä»yªk¦p¤U¡G

SaveToolbar Key, Subkey, Value

Key¬ORegistry¯Á¤ÞÁä¦WºÙ¡ASubKey¬ORegistry¤l¯Á¤ÞÁä¦WºÙ¡A¦ÓValue«h¬ORegistry­Èªº¦WºÙ¡F³o¨Ç°Ñ¼Æ©w¸q¤@­Ó¦b¨t²ÎRegistryªº¦ì¸m¡B¨äÀx¦s¤u¨ã¦Cªºª©­±¡C¨Ò¦p¡A¥i¨Ï¥Î¥¦­Ì¨Ì¾Ú¤£¦PªºÀ³¥Îµ{¦¡¦WºÙ¡Bµn¤Jªº¨Ï¥ÎªÌ»P¯S©wªº¤u¨ã¦C¨ÓÀx¦s¤£¦Pª©­±¡G

Private Sub Toolbar1_Change()
    Toolbar1.SaveToolbar "MyApplication", UserName, "MainFormToolbar"
End Sub

¨Ï¥ÎRestoreToolbar¤èªk¨ÓÁÙ­ì³]©w¡A¤@¯ë³£¦bForm_Load¨Æ¥óµ{§Ç¤º°õ¦æ¡G

Private Sub Form_Load()
    Toolbar1.RestoreToolbar "MyApplication", UserName, "MainFormToolbar"
End Sub

»¡©ú

«Ü©_©Çªº¡ARestoreToolbar¤èªk·|¤ÞµoChange¨Æ¥ó¡C³oºØ¦æ¬°³q±`¨SÃö«Y¡A¥u¬O¨Æ¥óµ{§Ç¤¤ªºµ{¦¡¦A«×§â¤u¨ã¦C¦s¨ìRegistry¤º½}¤F¡]¥u¤£¹L¦bªí³æ¸ü¤J®É¼W¥[¨Ç­t²ü¦Ó¤w¡^¡CµM¦Ó¡A¦pªGToolbarª«¥óªºChange¨Æ¥óµ{§Ç¥]§t¨ä¥L¡A¦p·¥¶O®Éªº±Ô­z¡A«h¥i¯à·|´îºCµ{¦¡¡A¬Æ¦Ü¤Þµo¤£¥i¹w´Áªº¿ù»~¡C


·í¦Û­q¤u¨ã¦C¹ï¸Ü¤è¶ô¶}±Ò®É¡A¨Ï¥ÎªÌ¥i§R°£¤w¦s¦bªº«ö¶s¡A«ì´_­ì¥ý³Q§R°£ªº«ö¶s¡A©Î§ïÅܤu¨ã¦C¤W«ö¶sªº¶¶§Ç¡C¦pªG­nÅý¨Ï¥ÎªÌ¼W¥[«ö¶s¡A¥²¶·¦b³]­p®É«Ø¥ß¨º¨Ç«ö¶s¡A°õ¦æ¸Óµ{¦¡¡A¯Ç¤J¦Û­q¤ÆToolbar¡A¨Ã§R°£³o¨ÇÃB¥~ªº«ö¶s¡C³Q§R°£ªº«ö¶s·|¦b¦Û­q¤u¨ã¦C¹ï¸Ü¤è¶ôªº¥ª¤è¤è¶ô¦Cªí¤¤¥X²{¡A¥H«KÅý¨Ï¥ÎªÌ«ì´_¤§¡C

TabStrip±±¨î¶µ
¡@

­¶ÅÒ¦¡¹ï¸Ü¤è¶ô¤w¦¨¬°WindowsÀ³¥Îµ{¦¡ªº¼Ð·Ç¡CVisual Basic¾Ö¦³¨â­Ó±±¨î¶µ¨Ó¹ê§@³oÃþ¹ï¸Ü¤è¶ô¡GTabStrip³q¥Î±±¨î¶µ©MSSTab±±¨î¶µ¡C²{¦b¥ý¤¶²ÐTabStrip±±¨î¶µ¡A ²Ä¤Q¤G³¹ ¦A¤¶²ÐSSTab±±¨î¶µ¡C

Ãö©óTabStrip±±¨î¶µ³Ì­«­nªº¤@¥ó¨Æ¬O¡G¥¦¨Ã¤£¬O¤@­Ó¦¬¯Ç¾¹¡]Container¡^¡A´«¥y¸Ü»¡¡A¥¦´£¨Ñ¤@­Ó¤¶­±¡A¨ä¥u¯àÅã¥Ü¤@¨Ç­¶ÅÒ©M¤ÏÀ³¨Ï¥ÎªÌ¹ï©ó¥¦ªºÂI¿ï¡C¶}µoªÌ»Ý¨Ì¾a­þ­Ó­¶ÅÒ³Q¿ï¨ú¨Ó¨M©w­þ¤@¸sªº±±¨î¶µ¬O§_Åã¥Ü¡C¦p¦¹·|¨Ï±o¹B¥Î¦¹±±¨î¶µÅܱo«Ü³Â·Ð¥B¥F¨ý¡A³o¤]´N¬O¬°¤°»ò³\¦h¶}µoªÌ¹ç¥i¿ï¥Î¯u¥¿ªº¦¬¯Ç¾¹¡A¥B¦b³]­p®É´N¥i¤Á´«­¶ÅÒªºSSTab±±¨î¶µ¡C¤£¹L¨Ìµ§ªÌªº·Qªk¡ATabStrip¦b¨ä¥L¤è­±ÁÙ¬O«Ü¦³¥Îªº¡C

TabStrip±±¨î¶µ¥]§tTabs¶°¦X¡A¨ä¨Ì¶¶§Ç¥]§tTabª«¥ó¡C±z¥²¶·¤F¸Ñ¨ä¬[ºc¥H«Kµ½¥Î¨ä¯à¤O¡C

³]©w³]­p¶¥¬qÄÝ©Ê
¡@

¦b©ñ¸mTabStrip±±¨î¶µ«á¡A¥²¶·³]©w¤@¯ëªºÄÝ©Ê¥B¼W¥[¨Ç­¶ÅÒ¡C¥i¥H¦bÄÝ©Ê­¶§¹¦¨³o¨â¶µ¤u§@¡A¶}±Òªº¤è¦¡¬°¦b±±¨î¶µ¤W«ö¥kÁä¨Ã¿ï¾ÜÄݩʿﶵ´N¯àÅã¥Ü¡C

¤@¯ë©ÊªºÄÝ©Ê
¡@

ÄÝ©Ê­¶ªº¤@¯ë­¶ÅÒ¥i³]©w¤@¯ë©ÊªºÄÝ©Ê¡A¦p¹Ï10-19©Ò¥Ü¡C²Ä¤@­Ó»Ý­n³]©wªºÄݩʬ°Style¡A¨ä¯à§ïÅܱ±¨î¶µªº¥~»ª¡C¤j³¡¤Àªº±¡ªp¤U«O«ù¬°¹w³]­È0-tabTabs¡]±±¨î¶µ¦¨¬°­¶ÅÒªº¶°¦X¡^§Y¥i¡A¤]¥i¥H³]¬°1-tabButtons¡]­¶ÅÒ·|¥Ñ«ö¶s©Ò¨ú¥N¡A¥BµL¥~®Ø¡^©Î2-tabFlatButtons¡]¦p¦PtabButtons¡A¦ý«ö¶s¬O¥­­±ªº¡^¡C¦b«á­±¨â­Ó¨Ò¤l¤¤¡A¥i¥H³]©wSeparatorsÄݩʬ°True¨Ó¹j¶}«ö¶s¡C³o¨Ç¼Ë¦¡ªº²Õ¦X¦p¹Ï10-20©Ò¥Ü¡C

TabFlatButton³]©w¬O­º¦¸¥X²{¦bVisual Basic 6¤¤¡ASeparatorÄݩʤ]¬O¡C¨ä¥LVisual Basic 6ªº·sÄÝ©ÊÁÙ¦³TabMinWidth¡BPlacement¡BTabStyle¡BHotTracking©MMultiSelect¡C


¡@

¹Ï10-19 TabStrip±±¨î¶µÄÝ©Ê­¶ªº¤@¯ë­¶ÅÒ¡C


¡@

¹Ï10-20 Ãö©óTabStrip±±¨î¶µªº¦UºØstyle¡C

¦pªG­nÅý­¶ÅÒ¤£¥þ¦b¦P¤@¦æ¥X²{ªº¸Ü¡A¥u­n±NMultiRowÄݩʳ]¬°True«K¥i«Ø¥ß¦h¦æªº­¶ÅÒ¡C¥i±NTabWidthStyleÄݩʳ]¬°0-tabJustified¡B1-tabNonJustified©Î2-tabFixed¨Ó¿ï¾Ü­¶ÅÒ¤£¦Pªº¼Ë¦¡¡C¦pªG­n­×¥¿­¶ÅÒ¼e«×¡A¥i½Õ¾ãTabFixedWidth©MTabFixedHeightÄÝ©Ê¡C­Y­¶ÅÒ¼e«×¬O¶·µø±¡ªp¦Ó©wªº¸Ü¡A¥i³]©wTabMinWidthÄݩʨӧ@¬°³Ì¤p¼e«×¡C

PlacementÄݩʨM©w­¶ÅÒ¥X²{ªº¦ì¸m¡A¦b±±¨î¶µªº³»ºÝ¡]¹w³]­È¡^¡B©³³¡¡B¥ª¤è©Î¥k¤èÃä®Ø¡CTabStyleÄÝ©Ê·|¼vÅT°õ¦æ®É¨ã¦³¦h¦æTabStrip±±¨î¶µªº¦æ¬°¡G·í³]¦¹Äݩʬ°1-tabTabOpposite®É¡A©Ò¦³¦b²{¦æ¦C¤§«eªº¦C·|Åã¥Ü¬Û¹ï©ó±±¨î¶µªº¥t¤@Ãä¡C

¤@¨Ç³]­p¶¥¬qªº¥¬ªLÄÝ©Ê·|¼vÅT±±¨î¶µªº¥~»ª¡C¥i³]©wHotTrackingÄݩʬ°True¨Ó±Ò°Ê§Y®É°lÂÜ¡]¦ý¥u¦bStyle¬°tabFlatButton®É¡^¡C¦pªGMultiselectÄݩʬ°True¡A«h¨Ï¥ÎªÌ¯àÂǥѫöµÛCtrlÁä¨Ó¿ï¾Ü¦h­Ó­¶ÅÒ¡C¡]¥u¦bStyle¬°tabButton©ÎtabFlatButton®É¡^¡C³Ì«á¡A­YShowTipsÄݩʬ°True®É¡A±±¨î¶µ·|Åã¥Ü·Æ¹«©Ò«ü¦V­¶ÅÒªºToolTipText¡C

Tabª«¥ó
¡@

·í³]©w¦n­«­nªº¤@¯ëÄÝ©Ê«á¡A´N¥i¦bÄÝ©Ê­¶ªºTabs­¶Åҫإ߭¶ÅÒ¡]¦³¨Ç²V²c¬O¶Ü¡H¨º¬O²Ä¤G­Ó­¶ÅÒ...¡^¡C°ß¤@ªº«D¿ï¾Ü©ÊÄݩʬOCaption¡CKeyÄݩʬO¥Î¨ÓÃѧOTabs¶°¦X¤¤ªº­¶ÅÒ¡A¦ÓTag©MToolTipTextªº·N¸q©M§@¥Î»P¥H©¹¬Û¦P¡C

¦b¨C­Ó­¶ÅÒ¥iÅã¥Ü¹Ï¥Ü¡C¦ý¥²¶·¸ü¤J©Ò¦³ªº¹Ï¤ù¨ìImageList±±¨î¶µ¤º¡AµM«á¦bTabStripªºImageListÄݩʤ¤¤Þ¥Î¦¹±±¨î¶µ¡CµM«á¡A¥i¥H±N­nÅã¥Ü¹Ï¤ùªº¯Á¤Þ«ü©wµ¹TabªºImageÄÝ©Ê¡C

·Ç³Æ¤l¦¬¯Ç¾¹
¡@

¦]¬°TabStrip±±¨î¶µ¤£¬O¦¬¯Ç¾¹±±¨î¶µ¡A©Ò¥HµLªkª½±µ±N¤l±±¨î¶µ©ñ¸m¦b¨äªí­±¡C³o¥i¯à¬O¦¹±±¨î¶µ³Ì¤jªº­­¨î¡G³o¹ï©ó±±¨î¶µ°õ¦æ®Éªº¯à¤O¨S¦³¼vÅT¡A¦ý«oÅý³]­p®ÉÅܱo¦³ÂI³Â·Ð¡C°õ¦æ®É¡A·í¬Y­¶ÅÒ³QÂI¿ï®É¡A¥²¶·Åã¥Ü¸Ó­¶ÅÒ¤º©Ò¦³ªº±±¨î¶µ¡A©MÄÝ©ó¨ä¥L­¶ÅÒªºÁôÂäl±±¨î¶µ¡C

¹ê»Ú¤W¡A³B²z¤l±±¨î¶µ³Ì¦X©yªº¤èªk¬O¦bªí³æ¤W«Ø¥ß¤@¨Ç¦¬¯Ç¾¹±±¨î¶µ-¨Ò¦p¡APictureBox©ÎFrame±±¨î¶µ¡C³o¨Ç±±¨î¶µÀ³§@¦¨±±¨î°}¦C¡A¥H«K®e©öºÞ²z¡C³o¨Ç¦¬¯Ç¾¹©ñ¦bªí³æªº­þ¸Ì¨Ã¤£­«­n¡A¦]¬°°õ¦æ®ÉÁÙ·|²¾°Ê»P§ïÅܨä¤j¤p¡C

°²³]²{¦b¦³­Ó¨ã¦³¤T­Ó­¶ÅÒªºTabStrip±±¨î¶µ¡C±z¥i¥H«Ø¥ß¤T­ÓPictureBox±±¨î¶µ¡A¦p¹ÏFigure 10-21©Ò¥Ü¡AµM«á§â¤l±±¨î¶µ©ñ¸m¦b¨C­ÓPictureBox¤º¡C½Ð§â¦¬¯Ç¾¹©ñ¦b¤£¦Pªº¦a¤è¡A¥H«K¦b³]­p®É¥i»´©ö¦a§ä¨ì¥¦­Ì¡A¨Ã¥ÎCtrl+JÁäÅý¥¦­Ì²¾¨ì³Ì¤W¼h¡C­Y¥ý³]©w¦¬¯Ç¾¹¦³¥i¨£ªºÃä®Ø¡AµM«á©ó°õ¦æ®É¦AÁôÂÃÃä®Ø«h·|°õ¦æ±o¸û¶¶ºZ¨Ç¡C


¡@

¹Ï10-21 ¨Ï¥ÎPictureBoxes¨Ó®e¯ÇTabStrip±±¨î¶µªº¤l±±¨î¶µ¡C

°õ¦æ¶¥¬qªº¹B§@
¡@

¤j¦h¼Æªº±¡ªp¤¤¡A¥u·|¨Ï¥ÎTabStrip±±¨î¶µªº³¡¥÷¥\¯à¡C¨Æ¹ê¤W¡A¤j¦h¼ÆªºÀ³¥Îµ{¦¡¥u»Ý­n¦b³]­p®É´ÁÅã¥Ü©w¸q­¶­±¡A«Ü¤Ö»Ý­n«Ø¥ß·sªº¡C¥»¸`±N»¡©úµ{¦¡¤¤Ãö©ó¦¹±±¨î¶µ³Ì±`¨Ï¥Îªº¥\¯à¡C

²¾°Ê»P§ïÅܦ¬¯Ç¾¹ªº¤j¤p
¡@

°²¦p§A·ÓµÛ¤§«eªº«Øij¡A¨Ï¥ÎFrame©ÎPictrueBox±±¨î¶µ§@¬°¤l±±¨î¶µªº¦¬¯Ç¾¹ªº¸Ü¡A¨º»ò¦bªí³æÅܦ¨¥i¨£«e¡A¥²¶·²¾°Ê¤Î§ïÅܨä¤j¤p¡C³o¨Ç°Ê§@³q±`·|¦bForm_Load¨Æ¥ó¤¤°õ¦æ¡A¨Ã³z¹LTabStrip±±¨î¶µªºClientLeft¡BClientTop¡BClientWidth¤ÎClientHeightÄÝ©Ê¥H±±¨î¨º¨Ç¦¬¯Ç¾¹À³­n²¾¨ì¦ó³B¡C°²¦p¥¦­Ì¦³Ãä®Øªº¸Ü¡A¤]»Ý­nÁôÂáC¤U¦Cªºµ{¦¡°²³]©Ò¦³ªºPictrueBox¦¬¯Ç¾¹±±¨î¶µÄÝ©ó¤@­ÓpicTab±±¨î¶µ°}¦C¡G

Private Sub Form_Load()
    Dim pic As PictureBox
    For Each pic In picTab
        pic.Move TabStrip1.ClientLeft, TabStrip1.ClientTop, _
            TabStrip1.ClientWidth, TabStrip1.ClientHeight
        pic.BorderStyle = 0
    Next
End Sub

¿ï¾Ü²{¦æ¦¬¯Ç¾¹
¡@

¹ï©ó¨Ï¥ÎªÌªºÂI¿ï°Ê§@¡A­n°µ¥X¤ÏÀ³¡ÐÅý³QÂI¿ï­¶ÅÒ©Ò¹ïÀ³ªº¦¬¯Ç¾¹¦¨¬°¥i¨£¡C³z¹LSelectItemÄÝ©Ê¥i±oª¾­þ­Ó­¶ÅÒ³QÂI¿ï¡C

Private Sub TabStrip1_Click()
    Dim pic As PictureBox
    For Each pic In picTab
        ' The expression on the right returns True for one picture box.
        ' (Control arrays are zero-based; Selected.Index is one-based.)
        pic.Visible = (pic.Index = TabStrip1.SelectedItem.Index - 1)
    Next     
End Sub

·íClick¨Æ¥ó¤Þµo®É¡ASelectedItemÄݩʪí¥Ü²{¦æªº­¶ÅÒ¡C­Y­nª¾¹DÂI¿ï«eªº­¶ÅÒ¬°¦ó¡A¥²¶·±N¦¹­È¦s©óªí³æ¼h¯ÅªºÅܼơC©ÎªÌ¥i¦bClick¨Æ¥ó¤Þµo«eªºBeforeClick¨Æ¥ó¤¤®·®»¨Ï¥ÎªÌªº°Ê§@¡C¦¹¨Æ¥óÅýµ{¦¡¦bÂ÷¶}²{¦æ­¶ÅÒ«e¡AÀˬd¨ä¸ê®Æªº¥¿½T©Ê¡A¤]¥iÂǦ¹¨ú®ø¦¹ÂI¿ï¡C¤U­±¬°½d¨Òµ{¦¡½X¡G

Private Sub TabStrip1_BeforeClick(Cancel As Integer)
    Select Case TabStrip1.SelectedItem.Index
        Case 1
            ' Refuse to move until the user types something in this field.
            If txtUserName.Text = "" Then Cancel = True
        Case 2
            ' Validation code for second tab
        Case 3
            ' Validation code for third tab
    End Select
End Sub

¤]¥i³z¹Lµ{¦¡¨Ó¿ï¾Ü­¶ÅÒ¡AÂǥѫü©w­Èµ¹SelectedItemÄݩʧY¥i¡C¥i¨Ï¥Î¤U¦C¨ä¤¤¤§¤@ªº»yªk¡G

' Both statements select the second tab.
Set TabStrip1.SelectedItem = TabStrip1.Tabs(2)
TabStrip1.Tabs(2).Selected = True

·í³z¹Lµ{¦¡¿ï¾Ü­¶ÅҮɡABeforeClick»PClick¨Æ¥ó¤]·|¤Þµo¡C

¦pªGTabStripªºMultiSelectÄݩʬ°Trueªº¸Ü¡A¥i¦P®ÉÅý¦h­ÓTabª«¥óªºSelectedÄݩʬ°True¡C¥i¥ÎDeselectAll¤è¦¡§Ö³t¦a¨ú®ø¿ï¨ú©Ò¦³­¶ÅÒ¡C³Ì«áÂǥѳ]©wHighlightedÄݩʬ°True¡A¥i±j½Õ¤@­Ó¥H¤Wªº­¶ÅÒ¦ÓµL¶·Åã¥Ü¨ä¤º®e¡G

' Highlight the second tab.
TabStrip1.Tabs(2).Highlighted = True

·s«Ø»P²¾°£Tabª«¥ó
¡@

¥i¦b°õ¦æ®É´Á·s«Ø­¶ÅÒ¡A¤èªk¬°¨Ï¥ÎTabs¶°¦XªºAdd¤è¦¡¡A»yªk¦p¤U¡G

Add([Index], [Key], [Caption], [Image]) As Tab

Add¤èªkªº°Ñ¼Æ¬°­n«Ø¥ßTabª«¥óªºIndex¡BKey¡BCaption»PImageÄÝ©Ê¡C¦]¬°¦¹¤èªk·|¶Ç¦^·s¼Wª«¥óªº¤Þ¥Î¡A¦]¦¹¥i¨Ï¥Î¤U¦C§Þ³N¨Ó³]©w¨ä¥LÄÝ©Ê¡G

With TabStrip1.Add(, , "Authentication")
    .ToolTipText = "Click here to change authentication settings"
    .Tag = "ABC123"
End With

¥i¦b°õ¦æ®É´Á¡A¥ÎTabs¶°¦XªºRemove¤è¦¡¨Ó²¾°£¦s¦bªºTabª«¥ó¡A¥B¥i¥Î¶°¦XªºClear¤è¦¡¨Ó²¾°£©Ò¦³­¶ÅÒ¡C

StatusBar±±¨î¶µ
¡@

³\¦hÀ³¥Îµ{¦¡·|¦bµøµ¡ªº©³³¡Åã¥Ü¸ê°T¡C¨Ï¥ÎªÌ¦bVisual Basic¸Ì«Ø¥ß¦¹ºØ¤¶­±³Ì²³æªº¤èªk¬O¨Ï¥ÎStatusBar±±¨î¶µ¡C

StatusBar±±¨î¶µ¥]§t¤@­ÓPanels¶°¦X¡A¨ä¤º§tPanelª«¥ó¡CPanelª«¥ó¬Oª¬ºA¦Cªº¤@­Ó°Ï°ì¡A¥iµ¹©w¼Ë¦¡¨ÓÅã¥Ü°T®§¡CStatusBar±±¨î¶µ´£¨Ñ¼ÆºØ¦Û°Êªº¼Ë¦¡¡]¨Ò¦pDate¡BTime»PShiftÁ䪺ª¬ºA¡^¡A¥[¤W³q¥ÎªºText¼Ë¦¡¡A¥i¦bPanelª«¥ó¤¤Åã¥Ü¥ô¦ó¦r¦ê¡CStatusBar±±¨î¶µÁÙ¦³Â²³æ¤å¦r¡]Simple Text¡^¼Ò¦¡¡A¨ä¥u¦³¤@­Ó¼e¼sªºPanelª«¥ó¡A¥Î¨ÓÅã¥Ü¸ûªøªº¤å¦r°T®§¡C

³]©w³]­p¶¥¬qÄÝ©Ê
¡@

ÄÝ©Ê­¶ªº¤@¯ë­¶ÅÒ©Ò¥]§tªºÄݩʨS¤°»ò¯S§Oªº¡C²z½×¤W¡A¥i³]©wStyleÄݩʬ°0-sbrNormal¡]¹w³]­È¡^©Î¬O1-sbrSimpleText¡A¥B¥i«ü©wSimpleTextÄÝ©Ê¡A¨äÅã¥Ü±N¦p¨ä¦W¡C¤£¹L¦b¹ê§@¤W¡A§Ú­Ì´X¥G¤£·|§ïÅܹw³]­È¡A¦]¬°«Ü¤Ö«Ø¥ß¥uÅã¥Ü¤å¦r°T®§ªºStatusBar±±¨î¶µ¡C¨Æ¹ê¤W¡A°²­Y­n¨º¼Ë°µªº¸Ü¡A³Ì¦n¥Î¸û³æ¯ÂªºLabel±±¨î¶µ©ÎAlign¬°vbAlignBottomªºPictureBox±±¨î¶µ¡C¦b¦¹­¶ÅÒ¤W¥t¤@­ÓÄݩʬ°ShowTips¡A¨äÅý¨C­ÓPanelª«¥óªºToolTipTextÄÝ©ÊÅܱo¥i¥Î¡C

²{¦b¨ìÄÝ©Ê­¶ªºPanels­¶ÅÒ¨Ó«Ø¥ßPanelª«¥ó¡A¦p¹Ï10-22©Ò¥Ü¡C¨C­ÓPanelª«¥ó¦³³\¦hÄÝ©Ê¥i¨M©w¨ä¥~Æ[»P¦æ¬°¡C¨ä¸û¦³½ìªºÄݩʬOStyle¡A¥¦¨M©w¤FPanel¤º³¡­nÅã¥ÜªºªF¦è¡C¨ä¹w³]­È¬O0-sbrText¡AÅã¥Ü¤FTextÄݩʪº¦r¦ê¡C±z¥i¨Ï¥ÎPanelª«¥ó§@¬°¯S®íÁ䪬ºAªº«ü¥Ü¡A±N¤§³]©w¬°1-sbrCaps¡B2-sbrNum¡B3-sbrIns©Î4-sbrScrl¨ä¤@§Y¥i¡C¤]¥i¥H±N¤§³]¦¨5-sbrTime©Î6-sbrDate¨Ó¦Û°Ê¦aÅã¥Ü²{¦bªº®É¶¡©Î¤é´Á¡C


¡@

¹Ï10-22 StatusBar±±¨î¶µÄÝ©Ê­¶ªºPanels­¶ÅÒ¡C

¦p¥ý«e©Ò»¡ªº¡A·íStyle¬°sbrText®É¡ATextÄݩʬOÅã¥Ü¦bPanelª«¥ó¤Wªº¦r¦ê¡CKey¬O¥Î¨ÓÃѧO¦bPanels¶°¦X¤¤Panelª«¥ó¤§¥i¿ï¾Üªº¯Á¤ÞÁä¡FTag»PToolTipTextªº·N¸q»P¥H©¹¬Û¦P¡CAlignmentÄݩʨM©wPanel¤º®eªº¦ì¸m¡]0-sbrLeft¡B1-sbrCenter©Î2-sbrRight¡^¡CBevelÄݩʨM©wPaneÃä¬Éªº§ÎºA¡G¨ä¹w³]­È¬O1-sbrInset¡A¦ý¥i§ï¬°2-sbrRaised©Î¿ï¾Ü¨S¦³3-DÃä¬Éªº0-sbrNoBevel¡C

MinWidthÄݩʬOPanelª«¥óªº­ì©l¤j¤p¡]³æ¦ì¬°twips¡^¡C·íªí³æªº¤j¤p¦³ÅܤƮɡAAutoSizeÄÝ©Ê·|¼vÅTPanelª«¥óªº¦æ¬°¡G¦Ó0-sbrNoAutoSize«Ø¥ßªº¬O©T©w¤j¤pªºPanel¡C1-sbrSpringªí¥ÜPanels·|ÀHµÛ¨ä¤÷ªí³æªº¤j¤p¦ÓÅܤơC¡]·í³\¦hPanels³£¦p¦¹³]©w®É¡A¥¦­Ì·|¬Û¹ï¦a¦¬ÁY©Î®i¶}¡^¡C2-sbrContents«hªí¥ÜPanelsªº¼e«×¨M©w©ó¨ä¤º®e¡C

¥i¥H¦bPanel¤ºÅã¥Ü¹Ï¥Ü©Î¹Ï¤ù¡C¥i©ó³]­p¶¥¬qÂǥѱqºÏºÐ¸ü¤J¹Ï¤ù¨Ó¹F¦¨³o­Ó¥\¯à¡Cª`·N¦b³q¥Î«¬±±¨î¶µ¤¤¡A³o¬O¨Ò¥~¨Æ¶µ¡A¤@¯ë¨Ó»¡¡A³o­Ó°Ê§@³£¬OÂÇ¥ÑImageList±±¨î¶µ¨Ó§¹¦¨¡C¦Ó³o¼Ë°µªº²z¥Ñ¬O¨C­ÓPanel¥i¯à·|¸ü¤J¤£¦P¤j¤pªº¹Ï¤ù¡A¦ÓImageList±±¨î¶µ¥u¯à¥]§t¬Û¦P¤j¤pªº¹Ï¤ù¡C

°õ¦æ¶¥¬qªº¹B§@
¡@

¦b°õ¦æ¶¥¬q¡A±z¤£·|·Q¦bStatusBar±±¨î¶µ¤W¶i¦æ¥ô¦ó¹B§@¡C¤£¹L¥i¯à»Ý­n¥h§ïÅܵ¹©wªºPanelª«¥ó¡]StyleÄݩʬO0-sbrText¡^ªºTextÄÝ©Ê¡A¦p¤U­±ªº¨Ò¤l¡G

' Display a message in the third panel.
StatusBar1.Panels(3).Text = "Hello World!"

¹ï©ó¸ûªøªº°T®§¡A¥i¥H§ïÅÜStatusBar±±¨î¶µªºStyleÄÝ©Ê¡A¥B«ü©w¸Ó¦r¦êµ¹¨äSimpleTextÄÝ©Ê¡G

' Display a message in the entire status bar.
StatusBar1.Style = sbrSimple
StatusBar1.SimpleText = "Saving data to file..."
' A lengthy operation
' ...
' Remember to restore the Style property.
StatusBar1.Style = sbrText

«Ø¥ß¤Î²¾°£Panelª«¥ó
¡@

¦b°õ¦æ®É´Á¡A«Ü¤Ö·|«Ø¥ß¤Î²¾°£Panelª«¥ó¡A¤£¹LÁÙ¬O±oª¾¹D·í»Ý­n®É¬O¥i¥H³o¼Ë°µªº¡C±z¥i¨Ï¥ÎPanels¶°¦XªºAdd¤èªk¹F¦¨¦¹°Ê§@¡A¨ä»yªk¦p¤U¡G

Add([Index], [Key], [Text], [Style], [Picture]) As Panel

¨C­Ó°Ñ¼Æ¹ïÀ³¨ì­n³Q«Ø¥ßªºPanelª«¥óªºÄÝ©Ê¡C¨Ò¦p¡A¤U¦Cµ{¦¡­n¦bStatusBar±±¨î¶µ³Ì¥ªÃ䪺¦ì¸m«Ø¥ß¤@­Ó·sªºPanel¡G

' Use Index = 1 to place this item before all other Panels.
With StatusBar1.Panels.Add(1, "temporary", "Hello World", sbrText)
    .Alignment = sbrCenter
    .Bevel = sbrNoBevel
    .AutoSize = sbrContents
End With

¥i¨Ï¥ÎPanels¶°¦XªºRemove¤è¦¡²¾°£³æ¤@Panelª«¥ó¡A¥B¥i¥ÎClear¤è¦¡²¾°£©Ò¦³Panelª«¥ó¡C

¦^À³¨Ï¥ÎªÌªº°Ê§@
¡@

StatusBar±±¨î¶µ¥]§t¤@¹ï¨Æ¥ó¡APanelClick»PPanelDblClick¡CÅU¦W«ä¸q¡A·í¨Ï¥ÎªÌ¹ïPanelª«¥ó«ö¤@¤U©Î³sÄò«ö¤G¤U·Æ¹«Áä®É·|¤Þµo³o¨Ç¨Æ¥ó¡C³Q«ö¤UªºPanel·|³Q·í¦¨¦¹¨Æ¥óªº°Ñ¼Æ¶Ç¤J¡C¤U¦Cµ{¦¡»¡©ú¤F¦p¦óÅý¨Ï¥ÎªÌÂǥѳsÄò«ö¤G¤U¨Ó­×§ïPanel¤º®e¡C

Private Sub StatusBar1_PanelDblClick(ByVal Panel As MSComctlLib.Panel)
    Dim s As String
    If Panel.Style = sbrText Then
        s = InputBox("Enter a new text for this panel")
        If Len(s) Then Panel.Text = s
    End If
End Sub

³Ð³y°ÊºA¹Ï¥Ü
¡@

Panelª«¥ó¥]§tPictureÄÝ©Ê¡C³q±`·|¦b³]­p¶¥¬q³]©w¦¹ÄÝ©Ê¡A¦ý¤]¥i«ü©w¹Ï¤ùµ¹¦¹ÄÝ©Ê¡C¨Ò¦p¥i¥Î¤£¦Pªº¹Ï¤ù«Ø¥ß°ÊºA¹Ï¥Ü¡C³o­Ó¬ªù¬O¥ý¸ü¤J©Ò¦³¹Ï¤ù¨ìImage±±¨î¶µ°}¦C¤º¡AµM«á¦bTimer±±¨î¶µªºTimer¨Æ¥ó¨ç¦¡¤¤¨Ì§Ç¦a«ü©w¡C¡]¨£¹Ï10-23.¡^

Private Sub Timer1_Timer()
    Static n As Integer
    ' Show the next image.
    StatusBar1.Panels("moon").Picture = imgMoon(n).Picture
    n = (n + 1) Mod 8
End Sub


¡@

¹Ï10-23 ½s¿è­±ªO¤å¦r¨Ã¶i¦æ²©ö°Êµeªº½d¨Òµ{¦¡¡C

Âê©wÁ䪬ºAªº¤Á´«
¡@

ÁöµMStatusBar±±¨î¶µ¯àÅã¥ÜCaps¡BNum¡BScroll¤ÎInsertÁ䪺ª¬ºA¡A¦ý«oµLªkÅý¨Ï¥ÎªÌ³z¹L·Æ¹«ªºÂI¿ï¨Ó¤Á´«¡]¦Ó³o¥i¯à¬O¤j¦h¼Æ¨Ï¥ÎªÌ·Q­nªº¡^¡C«Ü©¯¹B¦a¡A¥u»Ý­nÂÇ¥ÑAPI¨ç¼Æ¡A¨Ã¦bClick©ÎDblClick¨Æ¥ó¨ç¦¡¤¤¼¶¼g¨Çµ{¦¡½X´N¥i¹F¦¨³o¶µ¥\¯à¡G

' API declarations.
Declare Function GetKeyboardState Lib "user32" (KeyState As Byte) As Long
Declare Function SetKeyboardState Lib "user32" (KeyState As Byte) As Long

Private Sub StatusBar1_PanelDblClick(ByVal Panel As MSComctlLib.Panel)
    Select Case Panel.Style
        Case sbrCaps:  ToggleKey vbKeyCapital
        Case sbrNum:   ToggleKey vbKeyNumlock
        Case sbrScrl:  ToggleKey vbKeyScrollLock
        Case sbrIns:   ToggleKey vbKeyInsert
    End Select
    StatusBar1.Refresh
End Sub
Sub ToggleKey(vKey As KeyCodeConstants)
    Dim keys(255) As Byte
    ' Read the current state of the keyboard.
    GetKeyboardState keys(0)
    ' Toggle bit 0 of the virtual key we're interested in.
    keys(vKey) = keys(vKey) Xor 1
    ' Enforce the new keyboard state.
    SetKeyboardState keys(0)
End Sub

»¡©ú

Áö»¡ToggleKeyµ{§ÇÁ`¬O¹B§@±o«Ü¥¿±`¡A¤£¹Lµ§ªÌµo²{¦bWindows NT¨t²Î¤U¡AÁä½LLED«ü¥Ü¨Ã¤£·|¤ÏÀ³¤Á´«Á䪺·sª¬ºA¡C


©ñ¸m±±¨î¶µ¦bª¬ºA¦C¤W
¡@

ÁöµMStatusBar±±¨î¶µ´£¨Ñ³\¦hÄÝ©Ê¡A¦ý¤´¦³¨Ç¤£¨¬¡C¨Ò¦p¡A¤£¯à§ïÅÜ­Ó§OPanelª«¥óªº­I´ºÃC¦â¡A¤]¤£¯à¦bPanel¤ºÅã¥ÜProgressBar¡A³o¬O³\¦hWindowsÀ³¥Îµ{¦¡³£¦³ªº¯S¦â¡C«Ü©¯¹B¦a¡A¦³¤@­Ó²©öªº§Þ¥©¥i¥HÅý§A§JªA³o¨Ç­­¨î¡C

StatusBar±±¨î¶µ¤£¬O®e¯Ç¾¹¡A©Ò¥H¤£¯à¯uªº©ñ¸m¨ä¥L±±¨î¶µ-¨Ò¦pProgressBar-¨ìStatusBar¤º¡C¦ý¥i±N±±¨î¶µ©ñ¦bStatusBar¤W¡A¨Ï¤§¬Ý°_¨Ó´N¹³¦b¸Ì­±¤@¼Ë¡C³z¹LPanelª«¥óªºLeft¤ÎWidthÄÝ©Ê¥i¹F¦¨³o¼Ëªº®ÄªG¡C¤U¦Cµ{¦¡©ñ¸mProgressBar±±¨î¶µ©ó¯S©wªºPanel¤W¡A¼ÒÀÀ¶i¦æ¤¤ªºProgressBar¡AµM«á¦A«ì´_Panel­ì©l¥~Æ[¡G

Private Sub cmdProgress_Click()
    Dim deltaY As Single, pnl As Panel, v As Single
    ' Account for two pixels around the Panel.
    deltaY = ScaleY(2, vbPixels, vbTwips)
    ' Get a reference to the Panel object, and hide its bevel.
    Set pnl = StatusBar1.Panels(1)
    pnl.Bevel = sbrNoBevel
    ' Move the progress bar into position and in front of the status bar.
    ProgressBar1.Move pnl.Left, StatusBar1.Top + deltaY, _
        pnl.Width, StatusBar1.Height - deltaY
    ProgressBar1.Visible = True
    ProgressBar1.ZOrder
    
    ' Let the progress bar grow.
    For v = 1 To 100 Step 0.1
        ProgressBar1.Value = v
        DoEvents
    Next
    ' Restore original visibility state and bevel.
    ProgressBar1.Visible = False
    pnl.Bevel = sbrInset
End Sub

°²¦pªí³æ¬O¤£¯àÅܤƤj¤pªº¸Ü¡A«h¦¹§Þ¥©¬O«Ü§¹¬üªº¡C°£¦¹¤§¥~¡A·íªí³æ¬O¥iÅܤƤj¤p®É¡A¤]À³¸Ó²¾°ÊProgressBar±±¨î¶µ¡A¥u­n¦bForm_Resize¨Æ¥ó¤¤¥[¤J¾A·íªºµ{¦¡½X§Y¥i¡C¸Ô¨£ÀH®Ñ¥úºÐªº½d¨Òµ{¦¡­ì©l½X¡C

ProgressBar±±¨î¶µ
¡@

ProgressBar±±¨î¶µªº¥Î³~¬°§iª¾¨Ï¥ÎªÌ¸ûªø¹Bºâªº¶i«×¡C¦¹±±¨î¶µ¬OMsComCtl.OCXÀɮפºªº±±¨î¶µ¤¤³Ì²³æªº¡A¦]¬°¥¦¨S¦³¥ô¦ó¬ÛÃöª«¥ó¡A¥B¥¼¥]§t¥ô¦ó¦Û­q¨Æ¥ó¡C

³]©w³]­p¶¥¬qÄÝ©Ê
¡@

±NProgressBar±±¨î¶µ©ñ¸m©óªí³æ«á¡A¥²¶·©ó³]­p¶¥¬q³]©w´X­ÓÄÝ©Ê¡F¤j³¡¥÷±¡ªp¤U¡A±µ¨ü¹w³]­È§Y¥i¡C³Ì­«­nªºÄݩʬOMin»PMax¡A¨ä¨M©wProgressBar¥iÅã¥Üªº³Ì¤p¤Î³Ì¤j­È¡C

Visual Basic¤ºªºProgressBar±±¨î¶µ¥]¬A¨â­Ó·sÄÝ©Ê¡AOrientation¤ÎScrolling¡C«eªÌ¥i«Ø¥ß««ª½ªºProgressBar¡F«áªÌ¥i¿ï¾Ü¼Ð·Ç¶¡¹jª¬©Î¥­·Æª¬ªºProgressBar¡A¦p¹Ï10-24¡C¥ç¥i©ó°õ¦æ®É´Á§ïÅܳo¨Ç­È¡C

°õ¦æ¶¥¬qªº¹B§@
¡@

Ãö©óProgressBar±±¨î¶µ°õ¦æ®É´Áªº§@¥Î¨S¤°»ò¯S§Oªº¡C¹ê§@¤W¡A°ß¤@¶·³z¹Lµ{¦¡¨Ó§@ªº¥u¦³³]©wValueÄÝ©Ê­È¡]¶·¤¶©óMin¨ìMax¶¡¡^¡C­Yµ¹©wªº­È¤£¦bMin»PMax½d³ò¤º¡A·|¾É­P¿ù»~380¡u¤£¥¿½TªºÄÝ©Ê­È¡v¡C¦p¥ý«e©Ò´£ªº¡AProgressBar±±¨î¶µ¨S¦³¥ô¦ó¦Û­q¨Æ¥ó¡C


¡@

¹Ï10-24 ProgressBar±±¨î¶µªºOrientation¡BScrolling¡BAppearance»PBorderStyleÄݩʪº§@¥Î¡C

¥u¦³¨â­ÓÄÝ©Ê·|¼vÅT±±¨î¶µªº¥~Æ[-Appearance»PBorderStyle¡C¹Ï10-24Åã¥Ü¤F³o¨ÇÄÝ©Ê¥i¯àªº²Õ¦Xµ²ªG¡C

Slider±±¨î¶µ
¡@

Slider±±¨î¶µ¥Î¨ÓÅý¨Ï¥ÎªÌ¿ï¾Ü¤@©w½d³òªº¼Æ­È¡CÆ[©À¤W¡A¥¦ªñ¦üScrollBar±±¨î¶µ¡A³\¦hÄÝ©Ê¡B¨Æ¥ó¤]»P¥¦¬Û¦P¡C¥D­nªº®t§O¦b©ó¥u¦³¤@ºØSlider±±¨î¶µ¡A¨ä¥i«Ø¥ß««ª½»P¤ô¥­ªºSlider¡CSlider±±¨î¶µ¤]¤ä´©½d³ò¿ï¨ú¼Ò¦¡¡A¨ä¤¹³\¨Ï¥ÎªÌ¿ï¾Ü¤@­Ó½d³ò­È¦Ó¤£¬O³æ¤@­È¡C

³]©w³]­p¶¥¬qÄÝ©Ê
¡@

±NSlider±±¨î¶µ©ñ¸m©óªí³æ«á¡AÀ³¸Ó©ó¨ä¤W«ö·Æ¹«¥kÁä¨Ã¿ï¾ÜÄݩʿﶵ¡C¦bÄÝ©Ê­¶ªº ¤@¯ë ­¶ÅÒ¤¤¡A¥i³]©wMin¡BMax¡BSmallChange¤ÎLargeChangeÄÝ©Ê¡A¥¦­Ìªº·N¸q»Pµ²ªG»PHScrollBar¤ÎVscrollBar±±¨î¶µ¤@¼Ë¡C¦b¸Ó­¶ÅÒ¡AÁÙ¥i³]©wSelectRangeÄÝ©Ê¡A¦ý³o¶µ°Ê§@¤j¦h©ó°õ¦æ®É´Á¤~¶i¦æ¡C¡]¸Ô¨£¥»³¹µy«áªº ¡q½d³ò¿ï¨ú¼Ò¦¡¡r ¡^¡C

¦b¥~Æ[­¶ÅÒ¡A¥i³]©w¤Ö¼Æ¯SÄݩ󦹱±¨î¶µªºÄÝ©Ê¡COrientationÄݩʳ]©wSliderªº¤è¦V¡CTickStyleÄݩʨM©wSlider¬O§_­n¥X²{¨è«×»P¨äÅã¥Ü©ó¦ó³B¡C¡]¤¹³\ªº­È¬O0-sldBottomRight¡B1-sldTopLeft¡B2-sldBoth»P3-sldNoTicks¡^¡CTickFrequencyÄݩʶ¡±µ¨M©w­nÅã¥Ü¦h¤Ö¨è«×¡C¨Ò¦p¦pªGMin¬O0¤ÎMax¬O10¡]¹w³]³]©w¡^¡ATickFrequency­Y¬°2«h·|Åã¥Ü6­Ó¨è«×¡CTextPositionÄÝ©Ê·|¨M©wToolTip­nÅã¥Ü¦b­þ¸Ì¡C(¨£¥»³¹µy«áªº ¡qÅã¥ÜToolTip­È¡r )¡C

°õ¦æ¶¥¬qªº¹B§@
¡@

¦b¤j³¡¤Àªº¹ê§@¤¤¡A¥i¦b°õ¦æ®É´Á±NSlider±±¨î¶µ·í¦¨¬O±²¶b±±¨î¶µ¡GSlider±±¨î¶µ¥]§tValueÄݩʤÎChange¡BScroll¨Æ¥ó¡A¨ä§@¥Î©M±²¶b¬Û¦P¡C¤U¦C³¹¸`²µu¦a»¡©úSlider±±¨î¶µªº¨â­Ó¯S©Ê¡C

Åã¥ÜToolTip­È
¡@

·í«ü¥Ü¾¹³Q¨Ï¥ÎªÌ©ì¦²®É¡ASlider±±¨î¶µ¥iÀHµÛ«ü¥Ü¾¹¦ÓÅã¥ÜToolTip¡C¥i¨Ï¥ÎText»PTextPosition¨â­ÓÄÝ©Ê¥h±±¨î³o­Ó·sªºVisual Basic 6ªº¯S¦â¡C«eªÌ¬OÅã¥Ü¦bToolTip¤Wªº¦r¦ê¡F«áªÌ¨M©wToolTip¬Û¹ï©ó«ü¥Ü¾¹ªº¦ì¸m¡C¡]¨ä­È¥i¥H¬O0-sldAboveLeft»P1-sldBelowRight¡^¡C¤]¥i¥H¦b³]­p¶¥¬q¡A©óÄÝ©Ê­¶ªº¥~Æ[­¶ÅÒ¤¤³]©wTextPositionÄÝ©Ê¡C

³q±`·|¨Ï¥Î³o¨ÇÄݩʨÓÅã¥Ü¥Ø«eªºToolTip­È¡C¬°¤F¦p¦¹¡A¥u»Ý¦bScroll¨Æ¥óµ{§Ç¤¤¥[¤J¤U¦C±Ô­z¡G

Private Sub Slider1_Scroll()
    Slider1.Text = "Value = " & Slider1.Value
End Sub

½d³ò¿ï¨ú¼Ò¦¡
¡@

Slider±±¨î¶µ¥i¤ä´©Åã¥Ü½d³ò­È¦Ó«D³æ¤@­È¡A¦p¹Ï10-25©Ò¥Ü¡C¬°¤FÅã¥Ü¤@­Ó½d³ò¡A¶·³z¹L³\¦hÄÝ©Ê¡C­º¥ý¡AÂǥѳ]©wSelectRangeÄݩʭȬ°True¶i¤J½d³ò¿ï¨ú¼Ò¦¡¡Ð¨Ò¦p¡A·í¨Ï¥ÎªÌ«öµÛShiefÁäµM«áÂI¿ï±±¨î¶µ®É¡C

Dim StartSelection As Single 
Private Sub Slider1_MouseDown(Button As Integer, Shift As Integer, _
    x As Single, y As Single)
    If Shift = vbShiftMask Then
        ' If the shift key is being pressed, enter select range mode.
        Slider1.SelectRange = True
        Slider1.SelLength = 0
        StartSelection = Slider1.Value
    Else
        ' Else cancel any active select range mode.
        Slider1.SelectRange = False
    End If
End Sub


¡@

¹Ï10-25 ¥i¨Ï¥ÎSlider±±¨î¶µ¿ï¾Ü¤@­Ó½d³ò¡A¤]¥i¦b«ü¥Ü¾¹³Q©ì¦²®É©ó¨ä®ÇÅã¥ÜToolTip¡C

¦b¶i¤J½d³ò¿ï¨ú¼Ò¦¡«á¡A¥iÂÇ¥ÑSelStart¤ÎSelLengthÄݩʱ±¨î¿ï¨ú¶¡¹j¡C¥i¦bScroll¨Æ¥óµ{§Ç¤¤°µ³o¥ó¨Æ¡C¦]¬°SelLength¤£¥i¬O­t­È¡A©Ò¥H¥²¶·¤À¦¨¨âºØ®×¨Ò¨Ó³B²z¡G

Private Sub Slider1_Scroll()
    If Slider1.SelectRange Then
        ' The indicator is being moved in SelectRange mode.
        If Slider1.Value > StartSelection Then
            Slider1.SelStart = StartSelection
            Slider1.SelLength = Slider1.Value - StartSelection
        Else
            Slider1.SelStart = Slider1.Value
            Slider1.SelLength = StartSelection - Slider1.Value
        End If
    End If
End Sub

ImageCombo±±¨î¶µ
¡@

ImageCombo±±¨î¶µ¬Oªì¦¸¥]§t¦bVisual Basic¤º¡C·§¬A¦a»¡¡AImageCombo±±¨î¶µ¬O­Ó¤ä´©¹Ï¤ùªº¤U©Ô¦¡¤è¶ô¡A¥B¹ï¤£¦Pªº¶µ¥Ø¥i¦³¤£¦PªºÁY±Æ¡CWindows¤º³¡©Ò¨Ï¥ÎªºÀɮ׳q¥Î¹ï¸Ü¤è¶ô´N¬O¨Ï¥Î¦¹±±¨î¶µ¡C

¦Û³]­pªÌªºÆ[ÂI¨Ó¬Ý¡A ImageCombo±±¨î¶µ¤Î¼Ð·ÇComboBox±±¨î¶µ¥D­nªº¤£¦P¬OImageCombo±±¨î¶µ¨Ï¥Îª«¥ó¾É¦Vµ²ºc¡A¥B¥]§tComboItems¶°¦X¡A¥¦²[»\¤F©Ò¦³ªºComboItemª«¥ó¡C

³]©w³]­p¶¥¬qÄÝ©Ê
¡@

ImageCombo±±¨î¶µ»P¼Ð·ÇComboBox±±¨î¶µ«ÜÃþ¦ü¡A©Ò¥H¦b¦¹¥u°Q½×¨ä®t²§©Ê¡C©ó³]­p¶¥¬q¡A¥u»Ý­n³]©w¨â­ÓÄÝ©Ê¡CImageListÄݩʬOImageList±±¨î¶µªº¤Þ¥Î¡A¨ä¥]§t­nÅã¥Ü¦b¨C­ÓComboItemª«¥ó®Çªº¹Ï¤ù¡CIndentationÄݩʪí¥Ü©Ò¦³ComboItemª«¥ó¹w³]ªºÁY®æ¡A¨ä­Èªí¥ÜÁY±Æªº³æ¦ì¡A¨C­Ó³æ¦ì¬°10 pixel¡C¦Ó¦U¦ÛªºComboItemª«¥ó¥i¦Aµ¹¤©¤£¦Pªº­È©ó¦¹ÄÝ©Ê¡A¦p¦¹·|Âл\¹w³]­È¡]¹w³]­Èªº³]©w¥i©ó³]­p®É´Á¦bÄݩʵøµ¡µ¹©w©Î°õ¦æ®É´Á³z¹Lµ{¦¡¼¶¼g¡^¡C

»PComboBox±±¨î¶µ¤@¼Ë¡AImageCombo±±¨î¶µ¤]¥i³sµ²¨ì¬Y¸ê®Æ¨Ó·½¡A¥H¤ä´©©Ò¦³±`¨£ªºDataxxxxÄÝ©Ê¡C

°õ¦æ¶¥¬qªº¹B§@
¡@

ImageCombo±±¨î¶µ¥]§t³\¦hComboBox±±¨î¶µ©Ò¤ä´©ªºÄÝ©Ê¡A¥]¬AForeColor¡BBackColor¡BText¡BSelText¡BSelStart¡BSelLength»PLocked¡C¦Ó¥¦©Ò¤ä´©ªº¨Æ¥ó¡AComboBox³£¦³¡C

·í¼W¥[¶µ¥Ø©ó³o­Ó±±¨î¶µ®É¡A·|µo²{ImageCombo±±¨î¶µ¤ÎComboBox±±¨î¶µªº®t²§¡CImageCombo±±¨î¶µ¤£¤ä´©AddItem¤èªk¡C¬Û¤Ï¦a¡A¥i¥ÎComboItems¶°¦XªºAdd¤èªk¨Ó¼W¥[¶µ¥Ø¡A»yªk¦p¤U¡G

Add([Index],[Key],[Text],[Image],[SelImage],[Indentation]) As ComboItem

Index¨M©w·sªºComboItemªº¦ì¸m¡AKey¬O¨ä¦b¶°¦Xªº¯Á¤ÞÁä¡AText¬OÅã¥Üªº¦r¦ê¡AImage¬°ÃöÁpªº¹Ï¹³¡]¬°¨ä¦bImageList±±¨î¶µ¤ºªº¯Á¤Þ©Î¯Á¤ÞÁä¡^¡A·í¦¹¶µ¥Ø³Q¿ï¾Ü®É¡ASelImageªí¥Ü¨äÅã¥Üªº¹Ï¹³¡AIndentation¬°ÁY±Æµ¥¯Å¡]³æ¦ì¬°10 pixel¡^¡C¦¹»yªk¥i¼W¥[¤@­Ó·sªºComboItem¥B¥H¤@­Ó°Ê§@³]©w¨ä©Ò¦³ÄÝ©Ê¡C¤U¦C¬°¸ü¤J©Ò¦³ªººÏºÐ¾÷¥N¸¹»P¼ÐÅÒ¨ìImageCombo±±¨î¶µªº¨ç¦¡¡Aµ²ªG¦p¹Ï10-26©Ò¥Ü¡G

Sub LoadDrivesIntoImageCombo(ImgCombo As ImageCombo)
    Dim fso As New Scripting.FileSystemObject, dr As Scripting.Drive
    Dim drLabel As String, drImage As String
    ' Assume that the ImageCombo control is linked to an ImageList
    ' control that includes three icons with the following key names.
    ImgCombo.ComboItems.Add , , "My Computer", "MyComputer"
    For Each dr In fso.Drives
        ' Use a different image for each type of drive.
        Select Case dr.DriveType
            Case Removable:  drImage = "FloppyDrive"
            Case CDRom:      drImage = "CDDrive"
            Case Else:       drImage = "HardDrive"
        End Select
        ' Retrieve the letter and (if possible) the volume label.
        drLabel = dr.DriveLetter & ": "
        If dr.IsReady Then
            If Len(dr.VolumeName) Then drLabel = drLabel & "[" & _
                dr.VolumeName & "]"
        End If
        ' Add an indented item to the combo.
        ImgCombo.ComboItems.Add , dr.DriveLetter, drLabel, drImage, , 2
    Next
    ' Select the current drive.
    Set ImgCombo.SelectedItem = ImgCombo.ComboItems(Left$(CurDir$, 1))
 End Sub


¡@

¹Ï10-26 ImageCombo®i¥Üµ{¦¡Åã¥Ü¨t²Î¤¤©Ò¦³ºÏºÐ¾÷ªº¸ê°T¡C

³z¹Lµ{¦¡¿ï¾ÜComboItemª«¥ó¦³¨âºØ¤èªk¡G¥i¨Ï¥ÎImageCombo±±¨î¶µªºSelectedItemÄÝ©Ê¡]¦p¥ý«eªº¨ç¦¡¡^¡A©Î¥i³]©w­Ó§OComboItemª«¥óªºSelectedÄÝ©Ê¡C

' Select the current drive (alternative method).
Set ImgCombo.ComboItems(Left$(CurDir$, 1)).Selected = True

¥H­Ó§OªºComboItemª«¥ó¨Ó¹B§@®É¦³­Ó¦³½ìªº¦a¤è¡A¨º´N¬OµL¶·§R°£©Î¼W¥[¥¦«K¥i­×§ï¨äTextÄÝ©Ê¡A¥¿¦p¦P¹ï«Ý¼Ð·ÇComboBox¯ë¡G

' Change the text of the first item.
ImgCombo.ComboItems(1).Text = "My Computer"

¥i¨Ï¥ÎComboItems¶°¦XªºRemove¤è¦¡¨Ó§R°£­Ó§OªºComboItem¡A¦Ó­Y­n§R°£©Ò¦³ªº¶µ¥Ø¡A«h¥i¨Ï¥Î¶°¦XªºClear¤è¦¡¡C

ImageCombo±±¨î¶µ¥u¥]§t¤@­Ó¤è¦¡¡AGetFirstVisible¡A¨ä·|¶Ç¦^±±¨î¶µ²M³æ°Ï¤¤²Ä¤@­ÓComboItemª«¥óªº¤Þ¥Î¡C¤£¹L¦¹¤èªk¨S¤°»ò§@¥Î¡A¦]¬°¨S¦³¤èªkÅý¦¹²Ä¤@­Ó¶µ¥Ø¦¨¬°¥i¨£¡A¦]¦¹µLªk³z¹Lµ{¦¡±²°Ê²M³æ°Ïªº¤º®e¡C

¥H¤W¬°¥]§t¦bMsComCtl.ocxÀɮפº©Ò¦³±±¨î¶µªº»¡©ú¡C¤U¤@³¹¡A±N»¡©ú¨ä¥LVisual Basic 6©ÒªþªºWindows³q¥Î«¬±±¨î¶µ¡C