ÓÑÇéÌáʾ£ºÈç¹û±¾ÍøÒ³´ò¿ªÌ«Âý»òÏÔʾ²»ÍêÕû£¬Çë³¢ÊÔÊó±êÓÒ¼ü¡°Ë¢Ð¡±±¾ÍøÒ³£¡
¸»Ê¿¿µÐ¡ËµÍø ·µ»Ø±¾ÊéĿ¼ ¼ÓÈëÊéÇ© ÎÒµÄÊé¼Ü ÎÒµÄÊéÇ© TXTÈ«±¾ÏÂÔØ ¡ºÊղص½ÎÒµÄä¯ÀÀÆ÷¡»

VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ5²¿·Ö

¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿! Èç¹û±¾ÊéûÓÐÔĶÁÍ꣬ÏëÏ´μÌÐø½Ó×ÅÔĶÁ£¬¿ÉʹÓÃÉÏ·½ "Êղص½ÎÒµÄä¯ÀÀÆ÷" ¹¦ÄÜ ºÍ "¼ÓÈëÊéÇ©" ¹¦ÄÜ£¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡relate¡¡to¡¡each¡¡other¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Imagine¡¡building¡¡a¡¡car¡£¡¡A¡¡project¡¡could¡¡be¡¡the¡¡steering¡¡wheel£»¡¡engine£»¡¡or¡¡car¡¡body¡£¡¡Putting¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡all¡¡of¡¡the¡¡car¡¡projects¡¡together¡¡creates¡¡a¡¡plete¡¡solution¡¡called¡¡the¡¡car¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡A¡¡solution¡¡contains¡¡projects¡£¡¡For¡¡the¡¡examples¡¡in¡¡this¡¡chapter£»¡¡our¡¡solution¡¡will¡¡contain¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡three¡¡projects¡¡representing¡¡each¡¡of¡¡the¡¡three¡¡different¡¡program¡¡types¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡using¡¡Visual¡¡Basic¡¡Express£»¡¡creating¡¡a¡¡project¡¡implies¡¡creating¡¡a¡¡solution£»¡¡because¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡creating¡¡an¡¡empty¡¡solution¡¡without¡¡a¡¡project¡¡does¡¡not¡¡make¡¡sense¡£¡¡It¡¯s¡¡like¡¡building¡¡a¡¡car¡¡with¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡no¡¡parts¡£¡¡When¡¡I¡¡say¡¡¡°project¡±¡¡or¡¡¡°application¡±¡¡in¡¡this¡¡book£»¡¡from¡¡a¡¡workspace¡¡organization¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡perspective£»¡¡it¡¡means¡¡the¡¡same¡¡thing¡£¡¡Solution¡¡is¡¡an¡¡explicit¡¡reference¡¡to¡¡one¡¡or¡¡more¡¡projects¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡or¡¡applications¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Our¡¡plan¡¡of¡¡action¡¡in¡¡terms¡¡of¡¡projects¡¡and¡¡solutions¡¡in¡¡this¡¡chapter¡¡is¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Create¡¡the¡¡¡¡solution¡¡by¡¡creating¡¡a¡¡Windows¡¡application¡¡called¡¡WindowsApplication¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨creating¡¡this¡¡application¡¡also¡¡creates¡¡a¡¡solution£©¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Add¡¡to¡¡the¡¡created¡¡solution¡¡a¡¡console¡¡application¡¡called¡¡ConsoleApplication¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Add¡¡to¡¡the¡¡created¡¡solution¡¡a¡¡class¡¡library¡¡project¡¡called¡¡ClassLibrary¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Creating¡¡the¡¡Windows¡¡Application¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡We¡¯ll¡¡dive¡¡right¡¡in¡¡and¡¡start¡¡with¡¡the¡¡Windows¡¡application¡£¡¡With¡¡Visual¡¡Basic¡¡Express¡¡running£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡follow¡¡these¡¡steps¡¡to¡¡create¡¡the¡¡Windows¡¡application£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡£¡¡¡¡Select¡¡File¡¡¡¡New¡¡Project¡¡from¡¡the¡¡menu¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2¡£¡¡¡¡Select¡¡the¡¡Windows¡¡Forms¡¡Application¡¡icon¡£¡¡This¡¡represents¡¡a¡¡project¡¡style¡¡based¡¡on¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡predefined¡¡template¡¡called¡¡Windows¡¡Forms¡¡Application¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡27¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡C¡¡H¡¡AP¡¡TE¡¡R¡¡¡¡¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡R¡¡E¡¡AD¡¡Y¡¡£»¡¡¡¡¡¡ST¡¡E¡¡AD¡¡Y¡¡£»¡¡¡¡¡¡G¡¡O£¡¡¡5¡¡



¡¡¡¡¡¡¡¡¡¡¡¡3¡£¡¡Change¡¡the¡¡default¡¡name¡¡to¡¡WindowsApplication¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡4¡£¡¡Click¡¡OK¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡These¡¡steps¡¡create¡¡a¡¡new¡¡project¡¡and¡¡solution¡¡at¡¡the¡¡same¡¡time£º¡¡Visual¡¡Basic¡¡Express¡¡will¡¡¡¡

display¡¡only¡¡the¡¡plete¡¡project£»¡¡as¡¡shown¡¡in¡¡Figure¡¡1¡­2¡£¡¡



Figure¡¡1¡­2¡£¡¡¡¡The¡¡Visual¡¡Basic¡¡Express¡¡IDE¡¡with¡¡the¡¡new¡¡WindowsApplication¡¡project¡¡



Viewing¡¡the¡¡Source¡¡Code¡¡



When¡¡you¡¡create¡¡a¡¡new¡¡application£»¡¡Visual¡¡Basic¡¡Express¡¡automatically¡¡generates¡¡some¡¡source¡¡¡¡

code¡¡for¡¡it¡£¡¡Right¡­click¡¡the¡¡Form1¡£vb¡¡item¡¡in¡¡the¡¡Solution¡¡Explorer¡¡and¡¡select¡¡View¡¡Code¡¡from¡¡¡¡

the¡¡context¡¡menu¡£¡¡The¡¡following¡¡source¡¡code¡¡will¡¡appear¡¡in¡¡the¡¡area¡¡to¡¡the¡¡left¡¡of¡¡the¡¡Solution¡¡¡¡

Explorer¡£¡¡



¡öNote¡¡¡¡To¡¡shift¡¡between¡¡the¡¡user¡¡interface¡¡and¡¡generated¡¡code£»¡¡right¡­click¡¡Form1¡£vb¡¡in¡¡the¡¡Solution¡¡Explorer¡£¡¡A¡¡¡¡

submenu¡¡appears¡¡with¡¡the¡¡options¡¡View¡¡Code¡¡£¨to¡¡see¡¡the¡¡code£©¡¡or¡¡View¡¡Designer¡¡£¨to¡¡see¡¡the¡¡user¡¡interface£©¡£¡¡



Public¡¡Class¡¡Form1¡¡



End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡¡¡In¡¡Visual¡¡Basic£»¡¡the¡¡source¡¡code¡¡is¡¡spartan¡¡because¡¡Visual¡¡Basic¡¡is¡¡what¡¡was¡¡once¡¡called¡¡a¡¡¡¡

rapid¡¡application¡¡development¡¡£¨RAD£©¡¡environment¡£¡¡The¡¡idea¡¡at¡¡the¡¡core¡¡of¡¡Visual¡¡Basic¡¡is¡¡the¡¡¡¡

ability¡¡to¡¡develop¡¡an¡¡application¡¡as¡¡quickly¡¡as¡¡possible¡¡without¡¡the¡¡esoteric¡¡details¡¡of¡¡the¡¡language¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡28¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

6¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡R¡¡E¡¡A¡¡DY¡¡£»¡¡¡¡¡¡ST¡¡E¡¡A¡¡DY¡¡£»¡¡¡¡¡¡G¡¡O¡¡£¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡getting¡¡in¡¡your¡¡way¡£¡¡This¡¡legacy¡¡is¡¡both¡¡good¡¡and¡¡bad¡£¡¡Figure¡¡1¡­2¡¡shows¡¡a¡¡simple¡¡project¡¡with¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡single¡¡file£»¡¡but¡¡another¡¡file¡¡exists¡¡at¡¡the¡¡hard¡¡disk¡¡level£»¡¡as¡¡shown¡¡in¡¡Figure¡¡1¡­3¡¡£¨you¡¡can¡¡see¡¡this¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡file¡¡by¡¡clicking¡¡the¡¡Show¡¡All¡¡Files¡¡icon¡¡in¡¡the¡¡Solution¡¡Explorer¡¡and¡¡expanding¡¡the¡¡Form1¡£vb¡¡node£©¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡1¡­3¡£¡¡All¡¡files¡¡that¡¡make¡¡up¡¡the¡¡WindowsApplication¡¡project¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡previous¡¡versions£»¡¡the¡¡Form1¡£Designer¡£vb¡¡file¡¡used¡¡to¡¡be¡¡a¡¡binary¡¡file¡¡that¡¡you¡¡could¡¡not¡¡edit¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Now¡¡it¡¡is¡¡a¡¡text¡¡file¡¡that¡¡you¡¡can¡¡edit£»¡¡but¡¡you¡¡should¡¡not¡¡make¡¡any¡¡changes¡¡to¡¡this¡¡file¡¡because¡¡it¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡maintained¡¡by¡¡the¡¡IDE¡£¡¡Contained¡¡within¡¡the¡¡¡¡Form1¡£Designer¡£vb¡¡file¡¡are¡¡the¡¡details¡¡of¡¡how¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡construct¡¡Form1£»¡¡as¡¡is¡¡shown¡¡in¡¡Figure¡¡1¡­2¡£¡¡At¡¡this¡¡point£»¡¡Form1¡¡does¡¡not¡¡contain¡¡anything¡¡note

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡worthy£»¡¡and¡¡neither¡¡does¡¡the¡¡text¡¡file¡£¡¡However£»¡¡if¡¡you¡¡were¡¡to¡¡add¡¡a¡¡button¡¡or¡¡text¡¡box¡¡to¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡form£»¡¡those¡¡details¡¡would¡¡be¡¡added¡¡to¡¡the¡¡text¡¡file¡¡¡¡Form1¡£Designer¡£vb¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Visual¡¡Basic¡¡is¡¡a¡¡plete¡¡programming¡¡language¡¡that¡¡still¡¡adheres¡¡to¡¡the¡¡RAD¡¡model¡£¡¡For¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡example£»¡¡the¡¡following¡¡code¡¡creates¡¡a¡¡user¡­defined¡¡type¡¡£¨which¡¡you¡¯ll¡¡learn¡¡about¡¡throughout¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡rest¡¡of¡¡the¡¡book£©¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Class¡¡Example¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡Empty£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡main¡¡elements¡¡to¡¡note¡¡are¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class£º¡¡An¡¡organizational¡¡unit¡¡that¡¡groups¡¡related¡¡code¡¡together¡£¡¡This¡¡grouping¡¡is¡¡much¡¡more¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡specific¡¡than¡¡a¡¡solution¡¡or¡¡a¡¡project¡£¡¡To¡¡use¡¡the¡¡car¡¡analogy¡¡again£»¡¡if¡¡a¡¡project¡¡is¡¡a¡¡car¡¡engine£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡then¡¡a¡¡class¡¡can¡¡be¡¡the¡¡carburetor¡£¡¡In¡¡other¡¡words£»¡¡projects¡¡are¡¡made¡¡up¡¡of¡¡multiple¡¡classes¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Sub£º¡¡A¡¡set¡¡of¡¡instructions¡¡that¡¡carry¡¡out¡¡a¡¡task¡£¡¡Also¡¡called¡¡a¡¡method£»¡¡a¡¡sub¡¡is¡¡analogous¡¡to¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡function¡¡in¡¡many¡¡other¡¡languages¡£¡¡The¡¡¡¡Empty£¨£©¡¡method¡¡can¡¡be¡¡called¡¡by¡¡another¡¡piece¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡code¡¡to¡¡carry¡¡out¡¡some¡¡type¡¡of¡¡action¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Saving¡¡the¡¡Project¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡After¡¡you¡¯ve¡¡renamed¡¡the¡¡solution£»¡¡it¡¯s¡¡good¡¡practice¡¡to¡¡save¡¡your¡¡changes¡£¡¡To¡¡save¡¡the¡¡project£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡follow¡¡these¡¡steps£º¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡29¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡C¡¡H¡¡AP¡¡TE¡¡R¡¡¡¡¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡R¡¡E¡¡AD¡¡Y¡¡£»¡¡¡¡¡¡ST¡¡E¡¡AD¡¡Y¡¡£»¡¡¡¡¡¡G¡¡O£¡¡¡7¡¡



¡¡¡¡¡¡¡¡¡¡¡¡1¡£¡¡Highlight¡¡the¡¡project¡¡name¡¡in¡¡the¡¡Solution¡¡Explorer¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡2¡£¡¡Select¡¡File¡¡¡¡Save¡¡WindowsApplication¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡3¡£¡¡Notice¡¡that¡¡Visual¡¡Basic¡¡Express¡¡wants¡¡to¡¡save¡¡the¡¡solution¡¡using¡¡the¡¡WindowsApplication¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡name£»¡¡which¡¡isn¡¯t¡¡ideal¡£¡¡£¨We¡¯re¡¡using¡¡three¡¡projects¡¡in¡¡this¡¡solution£»¡¡of¡¡which¡¡one¡¡is¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Windows¡¡Forms¡¡application¡££©¡¡To¡¡save¡¡the¡¡solution¡¡with¡¡a¡¡new¡¡name£»¡¡you¡¡need¡¡to¡¡change¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡WindowsApplication¡¡solution¡¡name¡¡to¡¡ThreeExamples¡¡£¨make¡¡sure¡¡you¡¡leave¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡WindowsApplication¡¡project¡¡name¡¡as¡¡it¡¡is£©¡£¡¡Note¡¡the¡¡path¡¡of¡¡where¡¡Visual¡¡Basic¡¡Express¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡saves¡¡your¡¡projects£»¡¡as¡¡you¡¡will¡¡need¡¡to¡¡know¡¡it¡¡from¡¡time¡¡to¡¡time¡£¡¡



¡¡¡¡¡¡¡¡¡¡4¡£¡¡¡¡Click¡¡the¡¡Save¡¡button¡£¡¡



¡¡¡¡¡¡¡¡¡¡When¡¡the¡¡solution¡¡and¡¡project¡¡are¡¡successfully¡¡saved£»¡¡you¡¯ll¡¡see¡¡the¡¡message¡¡¡°Item£¨s£©¡¡Saved¡±¡¡¡¡

in¡¡the¡¡status¡¡bar¡¡in¡¡the¡¡lower¡­left¡¡corner¡¡of¡¡the¡¡window¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡future£»¡¡whenever¡¡you¡¡want¡¡to¡¡save¡¡the¡¡solution¡¡and¡¡project£»¡¡you¡¡can¡¡use¡¡the¡¡keyboard¡¡¡¡

shortcut£º¡¡Ctrl£«S¡£¡¡



¡öNote¡¡¡¡If¡¡you¡¡have¡¡not¡¡saved¡¡your¡¡changes¡¡and¡¡choose¡¡to¡¡exit¡¡Visual¡¡Basic¡¡Express£»¡¡you¡¡will¡¡be¡¡asked¡¡if¡¡you¡¡¡¡

want¡¡to¡¡save¡¡or¡¡discard¡¡the¡¡solution¡¡and¡¡project¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡To¡¡open¡¡a¡¡solution¡¡you¡¡have¡¡previously¡¡saved£»¡¡you¡¡can¡¡choose¡¡File¡¡¡¡Open¡¡Project¡¡at¡¡any¡¡¡¡

time¡¡and¡¡navigate¡¡to¡¡the¡¡solution¡¡file¡£¡¡You¡¡can¡¡also¡¡select¡¡the¡¡solution¡¡from¡¡the¡¡Recent¡¡Projects¡¡¡¡

window¡¡when¡¡you¡¡first¡¡start¡¡Visual¡¡Basic¡¡Express¡£¡¡The¡¡Recent¡¡Projects¡¡window¡¡is¡¡always¡¡avail

able¡¡on¡¡the¡¡Start¡¡Page¡¡tab¡¡of¡¡the¡¡main¡¡Visual¡¡Basic¡¡Express¡¡window¡¡as¡¡well¡¡£¨and¡¡the¡¡File¡¡menu¡¡¡¡

contains¡¡a¡¡list£»¡¡too£©¡£¡¡



Running¡¡the¡¡Windows¡¡Application¡¡



The¡¡source¡¡code¡¡generated¡¡by¡¡Visual¡¡Basic¡¡Express¡¡is¡¡a¡¡basic¡¡application¡¡that¡¡contains¡¡an¡¡empty¡¡¡¡

window¡¡with¡¡no¡¡functionality¡£¡¡The¡¡source¡¡code¡¡gives¡¡you¡¡a¡¡starting¡¡point¡¡where¡¡you¡¡can¡¡add¡¡¡¡

more¡¡source¡¡code£»¡¡debug¡¡the¡¡source¡¡code£»¡¡and¡¡run¡¡the¡¡application¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡To¡¡run¡¡the¡¡application£»¡¡select¡¡Debug¡¡¡¡Start¡¡Debugging¡£¡¡Alternatively£»¡¡use¡¡the¡¡keyboard¡¡¡¡

shortcut¡¡F5¡£¡¡You¡¯ll¡¡see¡¡a¡¡window¡¡representing¡¡the¡¡WindowsApplication¡¡application¡£¡¡You¡¡can¡¡exit¡¡¡¡

the¡¡application¡¡by¡¡clicking¡¡the¡¡window¡¯s¡¡close¡¡button¡£¡¡Figure¡¡1¡­4¡¡illustrates¡¡the¡¡process¡£¡¡¡¡

£¨Debugging¡¡is¡¡covered¡¡in¡¡Chapter¡¡5¡££©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡Running¡¡the¡¡application¡¡enables¡¡you¡¡to¡¡see¡¡what¡¡it¡¡does¡£¡¡When¡¡you¡¡run¡¡an¡¡application¡¡¡¡

though¡¡the¡¡IDE£»¡¡it¡¡is¡¡identical¡¡to¡¡a¡¡user¡¡clicking¡¡to¡¡start¡¡the¡¡application¡¡from¡¡the¡¡desktop¡£¡¡In¡¡this¡¡¡¡

example£»¡¡WindowsApplication¡¡displays¡¡an¡¡empty¡¡window¡¡without¡¡any¡¡controls¡¡or¡¡functionality¡£¡¡¡¡

The¡¡source¡¡code¡¯s¡¡functionality¡¡is¡¡to¡¡display¡¡an¡¡empty¡¡window¡¡when¡¡started¡¡and¡¡provide¡¡a¡¡button¡¡¡¡

to¡¡end¡¡the¡¡application¡¡£¨and¡¡buttons¡¡to¡¡maximize¡¡and¡¡minimize¡¡the¡¡window£©¡£¡¡Close¡¡the¡¡appli

cation¡¡now¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡30¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

8¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡R¡¡E¡¡A¡¡DY¡¡£»¡¡¡¡¡¡ST¡¡E¡¡A¡¡DY¡¡£»¡¡¡¡¡¡G¡¡O¡¡£¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡1¡­4¡£¡¡Running¡¡an¡¡application¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡You¡¡have¡¡not¡¡written¡¡a¡¡single¡¡line¡¡of¡¡code£»¡¡yet¡¡you¡¡have¡¡created¡¡an¡¡application¡¡and¡¡some

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡thing¡¡actually¡¡happened£»¡¡and¡¡all¡¡because¡¡Visual¡¡Basic¡¡Express¡¡generates¡¡some¡¡boilerplate¡¡Visual¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Basic¡¡code¡¡that¡¡works¡¡straight¡¡out¡¡of¡¡the¡¡box¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡You¡¡have¡¡created¡¡an¡¡application£»¡¡seen¡¡its¡¡source¡¡code£»¡¡and¡¡run¡¡it¡£¡¡You¡¡did¡¡all¡¡of¡¡this¡¡in¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡context¡¡of¡¡a¡¡fortable£»¡¡do¡­it¡­all¡­for¡­you¡¡development¡¡environment¡¡called¡¡Visual¡¡Basic¡¡Express¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Visual¡¡Basic¡¡Express¡¡is¡¡both¡¡a¡¡good¡¡thing¡¡and¡¡a¡¡bad¡¡thing¡£¡¡Visual¡¡Basic¡¡Express¡¡is¡¡good¡¡because¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡it¡¡hides¡¡the¡¡messy¡¡details£»¡¡but¡¡it¡¡is¡¡bad¡¡because¡¡the¡¡messy¡¡details¡¡are¡¡hidden¡£¡¡Imagine¡¡being¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡car¡¡mechanic¡£¡¡It¡¡is¡¡good¡¡that¡¡car¡¡manufacturers¡¡produce¡¡dashboards¡¡that¡¡have¡¡little¡¡lights¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡go¡¡on¡¡when¡¡something¡¡is¡¡wrong¡£¡¡But¡¡it¡¡would¡¡be¡¡bad¡¡if¡¡the¡¡mechanic¡¡had¡¡to¡¡rely¡¡on¡¡the¡¡little¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡lights¡¡to¡¡fix¡¡problems¡¡in¡¡a¡¡car¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Making¡¡the¡¡Windows¡¡Application¡¡Say¡¡Hello¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡Windows¡¡application¡¡does¡¡nothing¡¡other¡¡than¡¡appear¡¡with¡¡a¡¡blank¡¡window¡¡that¡¡you¡¡can¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡close¡£¡¡To¡¡make¡¡the¡¡application¡¡do¡¡something£»¡¡you¡¡need¡¡to¡¡add¡¡user¡¡interface¡¡elements¡¡or¡¡add¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡some¡¡code¡£¡¡Adding¡¡code¡¡without¡¡adding¡¡user¡¡interface¡¡elements¡¡will¡¡make¡¡the¡¡program¡¡do¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡something£»¡¡but¡¡it¡¯s¡¡not¡¡as¡¡exciting¡£¡¡So£»¡¡we¡¯ll¡¡add¡¡a¡¡button¡¡that£»¡¡when¡¡clicked£»¡¡will¡¡display¡¡¡°hello£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡world¡±¡¡in¡¡a¡¡text¡¡box¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡First£»¡¡you¡¡need¡¡to¡¡add¡¡the¡¡Button¡¡control¡¡to¡¡the¡¡form¡£¡¡Double¡­click¡¡Form1¡£vb¡¡in¡¡the¡¡Solution¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Explorer¡¡to¡¡display¡¡a¡¡blank¡¡form¡£¡¡Then¡¡click¡¡the¡¡Toolbox¡¡tab¡¡to¡¡access¡¡the¡¡controls¡¡and¡¡open¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mon¡¡Controls¡¡tab¡¡£¨click¡¡the¡¡pin¡¡icon¡¡on¡¡the¡¡Toolbox¡¡to¡¡leave¡¡the¡¡Toolbox¡¡tab¡¡open¡¡if¡¡you¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡31¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡C¡¡H¡¡AP¡¡TE¡¡R¡¡¡¡¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡R¡¡E¡¡AD¡¡Y¡¡£»¡¡¡¡¡¡ST¡¡E¡¡AD¡¡Y¡¡£»¡¡¡¡¡¡G¡¡O£¡¡¡9¡¡



like£©¡£¡¡Click¡¡Button£»¡¡and¡¡then¡¡click¡¡the¡¡form¡¡to¡¡place¡¡the¡¡button¡¡on¡¡the¡¡form¡£¡¡These¡¡steps¡¡are¡¡¡¡

illustrated¡¡in¡¡Figure¡¡1¡­5¡£¡¡



Figure¡¡1¡­5¡£¡¡Adding¡¡a¡¡button¡¡to¡¡the¡¡form¡¡



¡¡¡¡¡¡¡¡¡¡¡¡Next£»¡¡add¡¡a¡¡TextBox¡¡control¡¡using¡¡the¡¡same¡¡basic¡¡procedure¡£¡¡Finally£»¡¡align¡¡the¡¡button¡¡and¡¡¡¡

text¡¡box¡¡as¡¡shown¡¡in¡¡Figure¡¡1¡­6¡£¡¡To¡¡move¡¡a¡¡control£»¡¡use¡¡the¡¡handles¡¡that¡¡appear¡¡when¡¡you¡¡high

light¡¡the¡¡control¡£¡¡Visual¡¡Basic¡¡Express¡¡will¡¡align¡¡the¡¡edge¡¡of¡¡a¡¡control¡¡to¡¡nearby¡¡edges¡¡as¡¡you¡¡¡¡

drag¡¡it£»¡¡so¡¡that¡¡you¡¡can¡¡align¡¡controls¡¡accurately¡£¡¡



Figure¡¡1¡­6¡£¡¡Aligned¡¡button¡¡and¡¡text¡¡box¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡32¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

10¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡R¡¡E¡¡A¡¡DY¡¡£»¡¡¡¡¡¡ST¡¡E¡¡A¡¡DY¡¡£»¡¡¡¡¡¡G¡¡O¡¡£¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡you¡¡now¡¡executed¡¡WindowsApplication¡¡by¡¡pressing¡¡Ctrl£«F5¡¡£¨Ctrl£«F5¡¡starts¡¡the¡¡applica

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tion¡¡without¡¡debugging£©£»¡¡you¡¡would¡¡see¡¡a¡¡window¡¡with¡¡a¡¡button¡¡and¡¡a¡¡text¡¡box¡£¡¡You¡¡can¡¡click¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡button¡¡and¡¡add¡¡or¡¡delete¡¡text¡¡from¡¡the¡¡text¡¡box¡£¡¡But¡¡whatever¡¡you¡¡do¡¡has¡¡no¡¡effect£»¡¡because¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡neither¡¡control¡¡has¡¡been¡¡associated¡¡with¡¡any¡¡code¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡make¡¡the¡¡application¡¡do¡¡something£»¡¡you¡¡need¡¡to¡¡think¡¡in¡¡terms¡¡of¡¡events¡£¡¡For¡¡example£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡if¡¡you¡¡have¡¡a¡¡garage¡¡with¡¡an¡¡automatic¡¡door¡¡opener£»¡¡you¡¡would¡¡expect¡¡that¡¡pressing¡¡the¡¡remote¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡control¡¡button¡¡would¡¡open¡¡the¡¡garage¡¡door¡¡when¡¡it¡¯s¡¡closed¡¡and¡¡close¡¡the¡¡door¡¡when¡¡it¡¯s¡¡open¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡automatic¡¡garage¡¡door¡¡manufacturer¡¡associated¡¡the¡¡event¡¡of¡¡pushing¡¡the¡¡remote¡¡control¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡button¡¡with¡¡the¡¡action¡¡of¡¡either¡¡opening¡¡or¡¡closing¡¡the¡¡garage¡¡door¡£¡¡In¡¡WindowsApplication£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡we¡¯ll¡¡associate¡¡the¡¡clicking¡¡of¡¡the¡¡button¡¡with¡¡the¡¡action¡¡of¡¡showing¡¡text¡¡in¡¡the¡¡text¡¡box¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Select¡¡the¡¡button¡¡on¡¡the¡¡form¡¡in¡¡Visual¡¡Basic¡¡Express¡¡and¡¡double¡­click¡¡it¡£¡¡The¡¡work¡¡area¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡changes¡¡to¡¡source¡¡code£»¡¡with¡¡the¡¡cursor¡¡in¡¡the¡¡Button1_Click£¨£©¡¡function¡£¡¡Add¡¡this¡¡source¡¡code¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡the¡¡function£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡TextBox1¡£text¡¡=¡¡¡¨hello£»¡¡world¡¨¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡1¡­7¡¡illustrates¡¡the¡¡procedure¡¡for¡¡associating¡¡an¡¡event¡¡with¡¡an¡¡action¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡1¡­7¡£¡¡Associating¡¡the¡¡button¡¡click¡¡event¡¡with¡¡the¡¡¡¡action¡¡of¡¡adding¡¡text¡¡to¡¡the¡¡text¡¡box¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Note¡¡that¡¡TextBox1¡¡is¡¡the¡¡name¡¡of¡¡the¡¡text¡¡box¡¡you¡¡added¡¡to¡¡the¡¡form¡£¡¡This¡¡name¡¡is¡¡gener

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ated¡¡by¡¡Visual¡¡Basic¡¡Express£»¡¡just¡¡as¡¡it¡¡generated¡¡a¡¡default¡¡name¡¡for¡¡the¡¡button¡£¡¡You¡¡can¡¡change¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡default¡¡names¡¡£¨through¡¡each¡¡control¡¯s¡¡Properties¡¡window£©£»¡¡but¡¡we¡¯ve¡¡left¡¡the¡¡default¡¡for¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this¡¡example¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Adding¡¡an¡¡action¡¡to¡¡an¡¡event¡¡is¡¡very¡¡simple¡¡when¡¡following¡¡the¡¡instructions¡¡shown¡¡in¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡1¡­7¡£¡¡The¡¡simplicity¡¡is¡¡due¡¡to¡¡Visual¡¡Basic¡¡Express£»¡¡and¡¡not¡¡because¡¡the¡¡event¡¡or¡¡action¡¡is¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡33¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡C¡¡H¡¡AP¡¡TE¡¡R¡¡¡¡¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡R¡¡E¡¡AD¡¡Y¡¡£»¡¡¡¡¡¡ST¡¡E¡¡AD¡¡Y¡¡£»¡¡¡¡¡¡G¡¡O£¡¡¡11¡¡



simple¡£¡¡Visual¡¡Basic¡¡Express¡¡makes¡¡the¡¡assumption¡¡that¡¡when¡¡you¡¡double¡­click¡¡a¡¡control£»¡¡you¡¡¡¡

want¡¡to¡¡modify¡¡the¡¡¡¡default¡¡event¡¡of¡¡the¡¡control£»¡¡and¡¡as¡¡such£»¡¡automatically¡¡generates¡¡the¡¡code¡¡¡¡

in¡¡step¡¡3¡¡of¡¡Figure¡¡1¡­7¡£¡¡In¡¡the¡¡case¡¡of¡¡a¡¡button£»¡¡the¡¡default¡¡event¡¡is¡¡the¡¡click¡¡event£»¡¡that¡¡is£»¡¡the¡¡¡¡

event¡¡that¡¡corresponds¡¡to¡¡a¡¡user¡¡clicking¡¡the¡¡button¡£¡¡The¡¡assumption¡¡of¡¡the¡¡click¡¡event¡¡being¡¡¡¡

the¡¡default¡¡event¡¡for¡¡a¡¡button¡¡is¡¡logical¡£¡¡Other¡¡controls¡¡have¡¡different¡¡default¡¡events¡£¡¡For¡¡example£»¡¡¡¡

double¡­clicking¡¡a¡¡TextBox¡¡control¡¡will¡¡generate¡¡the¡¡code¡¡for¡¡the¡¡text¡­changed¡¡event¡£¡¡

¡¡¡¡¡¡¡¡¡¡Run¡¡the¡¡application¡¡by¡¡pressing¡¡Ctrl£«F5£»¡¡and¡¡then¡¡click¡¡the¡¡button¡£¡¡The¡¡text¡¡box¡¡fills¡¡with¡¡¡¡

the¡¡text¡¡¡°hello£»¡¡world¡£¡±¡¡Congratulations£»¡¡you¡¯ve¡¡just¡¡finished¡¡your¡¡first¡¡Visual¡¡Basic¡¡application¡£¡¡

¡¡¡¡¡¡¡¡¡¡You¡¡have¡¡associated¡¡an¡¡event¡¡with¡¡an¡¡action£º¡¡the¡¡button¡¡click¡¡with¡¡the¡¡text¡¡display¡£¡¡Associ

ating¡¡events¡¡with¡¡actions¡¡is¡¡the¡¡basis¡¡of¡¡all¡¡Windows¡¡applications¡£¡¡¡¡



Adding¡¡ments¡¡to¡¡the¡¡Application¡¡



Now¡¡that¡¡you¡¡have¡¡a¡¡working¡¡program£»¡¡it¡¡would¡¡be¡¡good¡¡to¡¡document¡¡what¡¡it¡¡does£»¡¡right¡¡there¡¡¡¡

in¡¡the¡¡source¡¡code¡£¡¡Then¡¡if¡¡you¡¡e¡¡back¡¡to¡¡the¡¡application¡¡in¡¡the¡¡future£»¡¡you¡¡won¡¯t¡¡be¡¡puzzled¡¡¡¡

by¡¡your¡¡pre
·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨11£© ²È£¨11£©
¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿!
ÎÂÜ°Ìáʾ£º ο´Ð¡ËµµÄͬʱ·¢±íÆÀÂÛ£¬Ëµ³ö×Ô¼ºµÄ¿´·¨ºÍÆäËüС»ï°éÃÇ·ÖÏíÒ²²»´íŶ£¡·¢±íÊéÆÀ»¹¿ÉÒÔ»ñµÃ»ý·ÖºÍ¾­Ñé½±Àø£¬ÈÏÕæдԭ´´ÊéÆÀ ±»²ÉÄÉΪ¾«ÆÀ¿ÉÒÔ»ñµÃ´óÁ¿½ð±Ò¡¢»ý·ÖºÍ¾­Ñé½±ÀøŶ£¡