友情提示:如果本网页打开太慢或显示不完整,请尝试鼠标右键“刷新”本网页!阅读过程发现任何错误请告诉我们,谢谢!! 报告错误
狗狗书籍 返回本书目录 我的书架 我的书签 TXT全本下载 进入书吧 加入书签

VB2008从入门到精通(PDF格式英文版)-第11章

按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 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 th
返回目录 上一页 下一页 回到顶部 0 0
未阅读完?加入书签已便下次继续阅读!
温馨提示: 温看小说的同时发表评论,说出自己的看法和其它小伙伴们分享也不错哦!发表书评还可以获得积分和经验奖励,认真写原创书评 被采纳为精评可以获得大量金币、积分和经验奖励哦!