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

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

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


¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Microsoft¡¡Visual¡¡Studio¡¡web¡¡site¡¡£¨http£º//msdn2¡£microsoft¡£/en¡­us/vstudio/default¡£aspx£©¡¡for¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡more¡¡information¡£¡¡If¡¡you¡¡already¡¡have¡¡Visual¡¡Studio¡¡2008¡¡Professional£»¡¡you¡¡can¡¡use¡¡that¡¡for¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡examples¡¡in¡¡this¡¡book¡£¡¡That¡¡edition¡¡can¡¡do¡¡everything¡¡that¡¡Visual¡¡Basic¡¡2008¡¡Express¡¡can¡¡do£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡in¡¡fact£»¡¡has¡¡many¡¡more¡¡options¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡I¡¡personally¡¡use¡¡Visual¡¡Studio¡¡Standard¡¡or¡¡Professional¡¡in¡¡bination¡¡with¡¡other¡¡tools¡¡such¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡as¡¡X¡­develop¡¡and¡¡JustCode£¡¡¡from¡¡Omnicore¡¡£¨http£º//omnicore¡££©£»¡¡TestDriven¡¡£¨¡¡http£º//¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡testdriven/£©£»¡¡and¡¡NUnit¡¡£¨¡¡http£º//nunit¡£org£©¡£¡¡The¡¡Visual¡¡Studio¡¡products¡¡are¡¡very¡¡good£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡but¡¡others¡¡are¡¡available¡£¡¡Being¡¡a¡¡good¡¡developer¡¡means¡¡knowing¡¡which¡¡tools¡¡work¡¡best¡¡for¡¡you¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Installing¡¡and¡¡downloading¡¡Visual¡¡Basic¡¡Express¡¡from¡¡the¡¡Microsoft¡¡web¡¡site¡¡involves¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡transfer¡¡of¡¡large¡¡files¡£¡¡If¡¡you¡¡do¡¡not¡¡have¡¡a¡¡broadband¡¡connection£»¡¡I¡¡suggest¡¡that¡¡you¡¡install¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡IDE¡¡from¡¡a¡¡CD¡¡instead¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Downloading¡¡Visual¡¡Basic¡¡Express¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡is¡¡the¡¡procedure¡¡for¡¡downloading¡¡Visual¡¡Basic¡¡Express¡¡from¡¡the¡¡Microsoft¡¡web¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡site¡£¡¡By¡¡the¡¡time¡¡you¡¡are¡¡reading¡¡this¡¡book£»¡¡the¡¡procedure¡¡may¡¡be¡¡a¡¡bit¡¡different£»¡¡but¡¡it¡¡will¡¡be¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡similar¡¡enough¡¡that¡¡you¡¯ll¡¡be¡¡able¡¡to¡¡find¡¡and¡¡download¡¡the¡¡IDE¡¡package¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡£¡¡¡¡Go¡¡to¡¡http£º//microsoft¡£/express/¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2¡£¡¡¡¡Select¡¡the¡¡Download¡¡Now£¡¡¡link¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡3¡£¡¡¡¡Scroll¡¡down¡¡to¡¡the¡¡Visual¡¡Basic¡¡2008¡¡Express¡¡Edition¡¡section£»¡¡as¡¡shown¡¡in¡¡Figure¡¡1¡­1¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡4¡£¡¡¡¡Click¡¡the¡¡Download¡¡link¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡5¡£¡¡¡¡A¡¡dialog¡¡box¡¡appears£»¡¡asking¡¡where¡¡you¡¡want¡¡to¡¡store¡¡the¡¡downloaded¡¡file¡£¡¡The¡¡file¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡you¡¡are¡¡downloading¡¡is¡¡a¡¡small¡¡bootstrap¡¡file£»¡¡which¡¡you¡¯ll¡¡use¡¡to¡¡begin¡¡the¡¡actual¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡installation¡¡of¡¡the¡¡Visual¡¡Basic¡¡Express¡¡IDE¡£¡¡Choose¡¡to¡¡save¡¡the¡¡file¡¡on¡¡the¡¡desktop¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡These¡¡steps¡¡can¡¡be¡¡carried¡¡out¡¡very¡¡quickly¡ªprobably¡¡within¡¡a¡¡few¡¡minutes¡£¡¡Do¡¡not¡¡mistake¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this¡¡procedure¡¡for¡¡downloading¡¡the¡¡plete¡¡Visual¡¡Basic¡¡Express¡¡application£»¡¡because¡¡that¡¯s¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡not¡¡what¡¡happened¡£¡¡The¡¡installation¡¡procedure¡¡will¡¡download¡¡the¡¡vast¡¡majority¡¡of¡¡the¡¡IDE¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡25¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



Figure¡¡1¡­1¡£¡¡Selecting¡¡Visual¡¡Basic¡¡2008¡¡Express¡¡Edition¡¡



Installing¡¡Visual¡¡Basic¡¡Express¡¡



After¡¡you¡¯ve¡¡downloaded¡¡the¡¡setup¡¡file£»¡¡you¡¡can¡¡start¡¡the¡¡Visual¡¡Basic¡¡Express¡¡installation¡£¡¡¡¡

During¡¡this¡¡process£»¡¡all¡¡the¡¡pieces¡¡of¡¡the¡¡IDE¡ªabout¡¡300MB¡ªare¡¡downloaded¡¡and¡¡installed¡£¡¡¡¡

Follow¡¡these¡¡steps£º¡¡



¡¡¡¡¡¡¡¡¡¡1¡£¡¡¡¡On¡¡your¡¡desktop£»¡¡double¡­click¡¡the¡¡vbsetup¡£exe¡¡file¡£¡¡Wait¡¡while¡¡the¡¡setup¡¡program¡¡loads¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡all¡¡the¡¡required¡¡ponents¡£¡¡



¡¡¡¡¡¡¡¡¡¡2¡£¡¡¡¡Click¡¡Next¡¡on¡¡the¡¡initial¡¡setup¡¡screen¡£¡¡



¡¡¡¡¡¡¡¡¡¡3¡£¡¡¡¡A¡¡series¡¡of¡¡dialog¡¡boxes¡¡will¡¡appear¡£¡¡Select¡¡the¡¡defaults¡¡and¡¡click¡¡Next¡¡to¡¡continue¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡through¡¡the¡¡setup¡¡program¡£¡¡In¡¡the¡¡final¡¡dialog¡¡box£»¡¡click¡¡Install¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡4¡£¡¡¡¡After¡¡all¡¡the¡¡elements¡¡have¡¡been¡¡downloaded¡¡and¡¡installed£»¡¡you¡¡may¡¡need¡¡to¡¡restart¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡your¡¡puter¡£¡¡



¡¡¡¡¡¡¡¡¡¡After¡¡Visual¡¡Basic¡¡Express¡¡is¡¡installed£»¡¡you¡¡can¡¡start¡¡it¡¡by¡¡selecting¡¡it¡¡from¡¡the¡¡Start¡¡menu¡£¡¡



Choosing¡¡the¡¡Application¡¡Type¡¡



With¡¡Visual¡¡Basic¡¡Express¡¡running£»¡¡you¡¯re¡¡ready¡¡to¡¡write¡¡your¡¡first¡¡¡¡application¡£¡¡However£»¡¡¡¡

first¡¡you¡¡need¡¡to¡¡make¡¡a¡¡choice£º¡¡what¡¡type¡¡of¡¡application¡¡will¡¡you¡¡write£¿¡¡Broadly¡¡speaking£»¡¡in¡¡¡¡

£»¡¡you¡¡can¡¡develop¡¡three¡¡main¡¡types¡¡of¡¡programs£º¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡26¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡A¡¡console¡¡application¡¡is¡¡designed¡¡to¡¡run¡¡at¡¡the¡¡mand¡¡line¡¡with¡¡no¡¡graphical¡¡user¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡interface¡¡£¨GUI£©¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡A¡¡¡¡Windows¡¡application¡¡is¡¡designed¡¡to¡¡run¡¡on¡¡a¡¡user¡¯s¡¡desktop¡¡and¡¡has¡¡a¡¡GUI¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡A¡¡class¡¡library¡¡holds¡¡reusable¡¡functionality¡¡that¡¡can¡¡be¡¡used¡¡by¡¡console¡¡and¡¡Windows¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡applications¡£¡¡It¡¡cannot¡¡be¡¡run¡¡by¡¡itself¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡So¡¡that¡¡you¡¡know¡¡what¡¡each¡¡type¡¡of¡¡program¡¡is¡¡about£»¡¡in¡¡this¡¡chapter£»¡¡you¡¡will¡¡code¡¡all¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡three¡£¡¡They¡¡are¡¡all¡¡variations¡¡of¡¡the¡¡Hello£»¡¡World¡¡example£»¡¡which¡¡displays¡¡the¡¡text¡¡¡°hello£»¡¡world¡±¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡on¡¡the¡¡screen¡£¡¡Hello£»¡¡World¡¡programs¡¡have¡¡been¡¡used¡¡for¡¡decades¡¡to¡¡demonstrate¡¡program

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ming¡¡languages¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Creating¡¡Projects¡¡and¡¡Solutions¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Regardless¡¡of¡¡which¡¡program¡¡type¡¡you¡¡are¡¡going¡¡to¡¡code£»¡¡when¡¡using¡¡the¡¡Visual¡¡Studio¡¡line¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡products£»¡¡you¡¡will¡¡create¡¡projects¡¡and¡¡solutions£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡A¡¡project¡¡is¡¡a¡¡classification¡¡used¡¡to¡¡describe¡¡a¡¡type¡¡of¡¡¡¡application¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡A¡¡solution¡¡is¡¡a¡¡classification¡¡used¡¡to¡¡describe¡¡multiple¡¡¡¡applications¡¡that¡¡most¡¡likely¡¡¡¡

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