10. µøµ¡³q¥Î«¬±±¨î¶µ¡G²Ä¤@³¡¥÷
µøµ¡³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ªGn¨Ï¥Î¸û·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«á¿ï¨ú±znªºOCX¬ÛÃö¿ï¶µ¡A¦p¹Ï10-2©Ò¥Ü¡C
·í±z¶i¤JVisual Basic 6Àô¹Ò¡AY±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¿ï±znªº¼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ªº´yz©Î¥]§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ªGnÅã²{ªí³æ¤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¦æ¤Wzªº°Ê§@¬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¦ýYn¤â°Ê¦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³¹ ¡CListImageª«¥ó¤]¥]§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¡AYn¨Ï¥Î¾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´º¦â¡BI´º¦âµ¥¥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ÓȪí¥Ü¤Wz¹Ï¥Ü©Òªí¥Ü¤¸¯Àªº¦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¨ºYnקï¸`Â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¡AY¦³Ó®Ú¸`Â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±zn©Ò¦³ªº¤ÀªK¬Ò¬O¤w±Æ§Çªº¡A¥²¶·³]©w¨CÓ¸`ÂIªºSortedÄݩʬ°True¡C
Visual Basic 6©ÒªþªºTreeView±±¨î¶µ¼W¥[¤F´XÓ¦³½ìªºÄÝ©Ê¡CFullRowSelectÄÝ©ÊÈY¬°True¡Aªí¥Ü¥unÂ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ÅܤơGYn®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ªº¥~Æ[¡CY³]©w¦¹Äݩʬ°True¡A·í·Æ¹«²¾¨ì¸`ÂI¤W¤è®É¡A·Æ¹«¹Ï¥Ü·|Åܦ¨¤âª¬¥B¸`ÂI¤å¦r·|¥X²{©³½u¡C
°õ¦æ¶¥¬qªº¹B§@
¡@
¬°¤Fn§¹¥þ´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¡AYn¥Î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ÄÝ©Ê«ht³dNode¿ï©w®É¨Ï¥Îªº¹Ï¹³¯Á¤ÞÈ¡FExpandedImageÄÝ©Ê«ht³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
¥unÂǥѼ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·Qn¹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ªº²Ó³¡¬OnÅý¨Ï¥ÎªÌ¤F¸Ñ¤@ÓNode¦p¦ó¾Ö¦³¤@өΦhÓ¤UÄݪ«¥ó¡A¦Ó¤£»Ýn¹ê»Ú¥h¼W¥[¥¦Ì¡C´«¥y¸Ü»¡¡A§ÚÌ»ÝnÅã¥Ü¥[¸¹¡AYNode¶µ¥Ø¦³¤U¼h¸ê®Æ®É¡C
nÃÒ©úTreeView³q¥Î±±¨î¶µ¯à°÷¦bNode®ÇÅã¥Ü¤@Ó¥[¸¹¦ÓµL»Ý¤lNodes¬O«Ü®e©öªº¡G¥un°õ¦æÀÉ®×Á`ºÞµ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«á±zn½Æ»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¦]¬°¥un§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¥un¨Ï¥ÎªÌ²¾°Ê·Æ¹«¨ì¶µ¥Øªº¤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·Qn±Æ§Ç¶µ¥Ø¡A´Nn±NSortedÄݩʳ]¬°True¡CSortKey«h¬O·Qn³Q±Æ§Çªº¦æªº¯Á¤Þ¡]²Ä¤@¦æ¬°0¡^¡A¦ÓSortOrder«h¬O±Æ§Çªº¶¶§Ç¡]0-lvwAscending©Î1-lvwDescending¡^¡A±z¥i¥H¦b°õ¦æ®É½Õ¾ã³o¨ÇÄÝ©Ê¡C
¸ê®Æ¦æ¦æº
¡@
³]p¶¥¬q®É¡A¥i«Ø¥ß¤@өΦhÓColumnHeaderª«¥ó¡A¥un¥ÎÄݩʹï¸Ü¤è¶ôªº¸ê®Æ¦æ¦æº¶ÅÒ¡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·QnŪ¨ú¤@±i¹Ï¤ù¨ì±±¨î¶µ¤¤¡A¥un¦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±±¨î¶µªº¥~»ª¡AYn¶ñ¤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¥DnListItemª«¥ó¤¤¦ì©ó¬Û¦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·QnŪ¨ú¸ê®Æ®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¥Î¤Uzªº¤èª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¤Uzªºµ{¦¡½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·Qn¥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·Qn°w¹ï¼Æ¦r©Î¤é´Á°µ±Æ§Ç¡A¥²¶·¥Î¨Ç§Þ¥©¡C«Ø¥ß¤@Ó·sªºColumnHeaderª«¥ó¡A¥H¦r¦ê¨Ó¶ñ¤J¡A¦Ó¦¹¦r¦ê¨Ó¦Û·Qn±Æ§Çªº¼Æ¦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¤Wzªºµ{¦¡µLªk³B²zt¼Æ¡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·Qn¥Îµ{¦¡¨Ó¶}©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Á|¨Ò¨Ó»¡¡An°µ¤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ÄÝ©Ê¡^¡CY¦³»Ý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¥un±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¥unÅã¥Ü¹Ï¥Ü¡A´N¤£n¿é¤J¥ô¦ó¦r¦ê¡^¡A¤@Ó«D¥²nªº¦Ûq±Ôz¡BTagÄÝ©Ê¡AButton¶°¦Xªº¯Á¤ÞÁä¡]«D¥²nªº¡A¦ý¥i¥Î¥¦¨Ó§ïµ½µ{¦¡ªº¥iŪ©Ê¡^¡AYToolbarªº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¬On³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
·Qn©ñ¸m¥ô¦ó±±¨î¶µ¦b¤u¨ã¦C¤W¡A¥i¥ý«Ø¥ßStyleÄݩʳ]¬°tbrPlaceholderªºButtonª«¥ó¡AµM«á²¾°Ê¸Ó±±¨î¶µ¨ì¾A·í¦ì¸m¡C¨Ò¦p¡An±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¼Ò¦¡¡CY¥un´£¨Ñ¦¹¯à¤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ªGnÅý¨Ï¥ÎªÌ¼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ªGnÅý¶ÅÒ¤£¥þ¦b¦P¤@¦æ¥X²{ªº¸Ü¡A¥un±NMultiRowÄݩʳ]¬°True«K¥i«Ø¥ß¦h¦æªº¶ÅÒ¡C¥i±NTabWidthStyleÄݩʳ]¬°0-tabJustified¡B1-tabNonJustified©Î2-tabFixed¨Ó¿ï¾Ü¶ÅÒ¤£¦Pªº¼Ë¦¡¡C¦pªGn×¥¿¶ÅÒ¼e«×¡A¥i½Õ¾ãTabFixedWidth©MTabFixedHeightÄÝ©Ê¡CY¶ÅÒ¼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³Ì«á¡AYShowTipsÄݩʬ°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±NnÅã¥Ü¹Ï¤ùªº¯Á¤Þ«ü©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¡CY¥ý³]©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¿ï°Ê§@¡An°µ¥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Äݩʪí¥Ü²{¦æªº¶ÅÒ¡CYnª¾¹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°²Yn¨º¼Ë°µªº¸Ü¡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¼Æ¨Ï¥ÎªÌ·Qnªº¡^¡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¥un¦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¶¡¡^¡CYµ¹©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¥Dnªº®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©wnÅã¥Ü¦h¤Ö¨è«×¡C¨Ò¦p¦pªGMin¬O0¤ÎMax¬O10¡]¹w³]³]©w¡^¡ATickFrequencyY¬°2«h·|Åã¥Ü6Ó¨è«×¡CTextPositionÄÝ©Ê·|¨M©wToolTipnÅã¥Ü¦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¬OtÈ¡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±±¨î¶µ¥Dnªº¤£¦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¨ä¥]§tnÅã¥Ü¦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¦ÓYn§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