2. SOFTWARE DEVELOPMENT

2.1 Overview of .Net Framework
The .NET Framework is a new computing platform that simplifies application development in the highly distributed environment of the Internet. The .NET Framework is designed to fulfil the following objectives.
To provide a consistent object-oriented programming environment whether object code is stored and executed locally, executed locally but Internet-distributed, or executed remotely.
To provide a code-execution environment that minimizes software development and versioning conflicts.
To provide a code-execution environment that guarantees safe execution of code, including code created by an unknown or semi-trusted third party.
To provide a code-execution environment that eliminates the performance problems of scripted or interpreted environments.
To make the developer experience consistent across widely varying types of applications, such as Windows-based applications and Web-based applications.
To build all communication on industry standards to ensure that code based on the .NET Framework can integrate with any other code.
The .NET Framework has two main components: the common language runtime and the .NET Framework class library. The common language runtime is the foundation of the .NET Framework. You can think of the runtime as an agent that manages code at execution time, providing core services such as memory management, thread management, and remoting, while also enforcing strict type safety and other forms of code accuracy that ensure security and robustness. In fact, the concept of code management is a fundamental principle of the runtime. Code that targets the runtime is known as managed code, while code that does not target the runtime is known as unmanaged code.
The class library, the other main component of the .NET Framework, is a comprehensive, object-oriented collection of reusable types that you can use to develop applications ranging from traditional command-line or graphical user interface (GUI) applications to applications based on the latest innovations provided by ASP.NET, such as Web Forms and XML Web services
The .NET Framework can be hosted by unmanaged components that load the common language runtime into their processes and initiate the execution of managed code, thereby creating a software environment that can exploit both managed and unmanaged features. The .NET Framework not only provides several runtime hosts, but also supports the development of third-party runtime hosts.
For example, ASP.NET hosts the runtime to provide a scalable, server-side environment for managed code. ASP.NET works directly with the runtime to enable ASP.NET applications and XML Web services.
The following illustration shows relationship of the common language runtime and the class library to your applications and to the overall system. The illustration also shows how managed code operates within a larger architecture.
2.2 .NET Framework in context
The following sections describe the main components and features of the .NET Framework in greater detail.
2.3 Features of the Common Language Runtime
The common language runtime manages memory, thread execution, code execution, code safety verification, compilation, and other system services. These features are intrinsic to the managed code that runs on the common language runtime.
With regards to security, managed components are awarded varying degrees of trust, depending on a number of factors that includes their origin (such as the Internet, enterprise network, or local computer). This means that a managed component might not might not be able to perform file-access operations, registry-access operations, or other sensitive functions, even if it is being used in the same active application.
The runtime enforces code access security. For example, users can trust that an executable in a Web page can play an animation on screen or sing a song, but cannot access their personal data, file system, or network. The security features of the runtime thus enable legitimate Internet-deployed software to be exceptionally featuring rich.
The runtime also enforces code robustness by implementing a strict type-and –code verification infrastructure called the common type system (CTS). The CTS ensures that all managed code is self-describing. The various Microsoft and Third-party language compilers generate managed code that conforms to the CTS. This means that manages code can consume other managed types and instances, while strictly enforcing type fidelity and type safety.
In addition, the managed environment of the runtime eliminates many common software issues. For example, the runtime automatically handles object layout and manages references to objects, releasing them when they are no longer being used. This automatic memory management resolves the two most common application errors, memory leaks and invalid memory references.
The runtime also accelerates developer’s productivity. For example, programmers can write applications in their development language of choice, yet take full advantage of the runtime, the class library, and components written in other languages by other developers. Any compiler vendor who chooses to target the runtime can do so. Language compilers that target that .NET Framework make the features of the .NET Framework available to existing code written in that language, greatly easing the migration process for existing applications.
While the runtime is designed for the software’s of the failure, it also supports software of today and yesterday. Interoperability between managed and unmanaged code enables developers to continue to use necessary COM components and DLLs.
The runtime is designed to enhance performance. Although the common language runtime provides many standards runtime services, managed code is never interpreted. A feature called just-in-time (JIT) compiling enables all managed code to run in the native machine language of the system on which it is executing. Meanwhile, the memory manager removes the possibilities of fragmented memory and increases memory locality of reference to further increase performance.
Finally, the runtime can be hosted by high-performance, server-side applications, such as Microsoft SQL Server and Internet Information Services (IIS). This infrastructure enables you to use managed code to write your business logic, while still enjoying the superior performance of the industry’s best enterprise servers that support runtime hosting.
2.4 .NET Framework Class Library
The .NET Framework class library is a collection of reusable types that tightly integrate with the common language runtime. The class library is object oriented, providing types from which your own managed code can derive functionality. This not only makes the .NET Framework types easy to use, but also reduces the time associated with learning new features of the .NET Framework. In addition, third party components can integrate seamlessly with classes in the .NET Framework.
For example, the .NET Framework collection classes implement a set of interfaces that you can use to develop your own collection classes. Your collection classes will blend seamlessly with the classes in the .NET Framework.
As you would expect from an object-oriented class library, the .NET Framework types enables you to accomplish a range of common programming tasks, including tasks such as string management, data collection, database connectivity, and file access.
In addition to these common tasks, the class library includes types that support a variety of specialized development scenarios. For example, you can use the .NET Framework to develop the following types of applications and services:
Console applications.
Windows GUI applications (Windows Forms).
ASP.NET applications.
XML Web services.
Windows services.
For example, the Windows Forms classes are a comprehensive set of reusable types that vastly simplify Windows GUI development. If you write an AP.NET Web Form application, you ca use the Web Forms classes.
2.5 Client Application Development
Client applications are the closest to a traditional style of application in Windows-based programming. These are the types of applications that display windows or forms on the desktop, enabling a user to perform a task. Client applications include applications such as word processors and spreadsheets, as well as custom business applications such as data-entry tools, reporting tools, and so on. Client applications usually employ windows, menus, buttons, and other GUI elements, and they likely access local resources such as the file system and peripherals such as printers.
Another kind of client application is the tradition ActiveX control (now replaced by the managed Window Forms control) deployed over the Internet as a Web page. This application is much like other client applications: it is executed natively, has access to local resources, and includes graphical elements.
In the past, developers created such applications using C? C++ in conjunction with the Microsoft Foundation Classes (MFC) or with a rapid application development (RAD) environment such as Microsoft visual Basic.
The .NET Framework incorporates aspects of these existing products into a single, consistent development environment drastically simplifies the development of client applications.
The Windows Forms classes contained in the .NET Framework are designed to be used for GUI development. You can easily create command windows, buttons, menus, toolbars, and other screen elements with the flexibility necessary to accommodate shifting business needs.
For example, the .NET Framework provides simple properties to adjust visual attributes associated with forms. In some cases underlying operating system does not support changing these attributes directly, and in these cases the .NET Framework automatically recreates the forms. This is one of many ways in which the .NET Framework integrates the developer interface, making coding simpler and more consistent.
Unlike ActiveX controls, Windows Forms controls have semi-trusted access to a user’s computer. This means that binary or natively executing code can access some of the resources on the user’s system (such as GUI elements and limited file access) without being able to access or compromise other resources. Because of code access security, many applications that once needed to be installed on a user’s system cam now are safely deployed through the Web. Your applications can implements the feature of a local application while being deployed like a Webpage.
2.6 Server Application Development
Server-side applications in the managed world are implemented through runtime hosts. Unmanaged applications host the common language runtime. Which allows your custom managed code to control the behaviour of the server. This model provides you with all the features of the common language runtime and class while gaining the performance and scalability of the server.
The following illustration shows a basic network schema with managed code running in different server environments. Servers such as IIS and SQL Server can perform standard operations while your applications logic executes through the managed code.
Server-side managed code into the highly distributed environment of the Internet.
If you have used earlier versions of ASP technology, you will immediately notice the improvements that ASP.NET and Web Forms offers. For example, you can develop Web Forms pages in any language that supports the .NET Framework. In addition, your code no longer needs to share the same file with your HTTP text (although it can continue to do so if you prefer). Web Forms pages execute in native machine language because, like another managed application, they take full advantage of the runtime. In contrast, unmanaged ASP pages are ASP.NET is the hosting environment that enables developers to use the .NET Framework to target Web-based applications. However, ASP.NET is more that just a runtime host: it is a complete architecture for developing Web sites and Internet-distributed objects using managed code. Both Web Forms and XML Web services use IIS and ASP.NET as the publishing mechanism for applications, and both have a collection of supporting in the .NET Framework.
XML Web services, an important evolution in Web based technology, are distributed, server-side application component similar to common Web sites. However, unlike Web-based applications, XML Web services components have no UI and are not targeted for browsers such as Internet Explorer and Netscape Navigator. Instead, XML Web services consists of reusable software components designed to be consumed by other applications, such as traditional client applications, Web-based applications, or even other XML Web services.
As a result, XML Web services technology is rapidly moving application developing and deployment always scripted and interpreted. ASP.Net pages are faster, more functional, and easier to develop than unmanaged ASP pages because they interact with the runtime like any managed application.
The .Net Framework also provides a collection of classes and tools to aid in development and consumption of XML Web services. XML Web services applications. XML Web services are built on standards such as SOAP (a remote procedural-call protocol), XML (an extensible data format), and WSDL (the Web services Description Language). The .NET Framework is built on these standards to promote interoperability with non-Microsoft solutions.
WHAT IS .NET
.NET “is the XML Web services platforms, a way of working that allows you to create software as a service.” It’s a Microsoft vision based on distributed computing, the dream of sharing information over the Internet, no matter what operating system, devices, or programming language you’re using.
According to our favourite software giant, this .NET plan covers five core areas, not all of which have yet been fulfilled:
With regards to security, managed components are awarded varying degrees of trust, depending on a number of factors that includes their origin (such as the Internet, enterprise network, or local computer). This means that a managed component might not might not be able to perform file-access operations, registry-access operations, or other sensitive functions, even if it is being used in the same active application.
The runtime enforces code access security. For example, users can trust that an executable in a Web page can play an animation on screen or sing a song, but cannot access their personal data, file system, or network. The security features of the runtime thus enable legitimate Internet-deployed software to be exceptionally featuring rich.
The runtime also enforces code robustness by implementing a strict type-and –code verification infrastructure called the common type system (CTS). The CTS ensures that all managed code is self-describing. The various Microsoft and Third-party language compilers generate managed code that conforms to the CTS. This means that manages code can consume other managed types and instances, while strictly enforcing type fidelity and type safety.
In addition, the managed environment of the runtime eliminates many common software issues. For example, the runtime automatically handles object layout and manages references to objects, releasing them when they are no longer being used. This automatic memory management resolves the two most common application errors, memory leaks and invalid memory references.
The runtime also accelerates developer’s productivity. For example, programmers can write applications in their development language of choice, yet take full advantage of the runtime, the class library, and components written in other languages by other developers. Any compiler vendor who chooses to target the runtime can do so. Language compilers that target that .NET Framework make the features of the .NET Framework available to existing code written in that language, greatly easing the migration process for existing applications.
While the runtime is designed for the software’s of the failure, it also supports software of today and yesterday. Interoperability between managed and unmanaged code enables developers to continue to use necessary COM components and DLLs.
The runtime is designed to enhance performance. Although the common language runtime provides many standards runtime services, managed code is never interpreted. A feature called just-in-time (JIT) compiling enables all managed code to run in the native machine language of the system on which it is executing. Meanwhile, the memory manager removes the possibilities of fragmented memory and increases memory locality of reference to further increase performance.
Finally, the runtime can be hosted by high-performance, server-side applications, such as Microsoft SQL Server and Internet Information Services (IIS). This infrastructure enables you to use managed code to write your business logic, while still enjoying the superior performance of the industry’s best enterprise servers that support runtime hosting.
2.4 .NET Framework Class Library
The .NET Framework class library is a collection of reusable types that tightly integrate with the common language runtime. The class library is object oriented, providing types from which your own managed code can derive functionality. This not only makes the .NET Framework types easy to use, but also reduces the time associated with learning new features of the .NET Framework. In addition, third party components can integrate seamlessly with classes in the .NET Framework.
For example, the .NET Framework collection classes implement a set of interfaces that you can use to develop your own collection classes. Your collection classes will blend seamlessly with the classes in the .NET Framework.
As you would expect from an object-oriented class library, the .NET Framework types enables you to accomplish a range of common programming tasks, including tasks such as string management, data collection, database connectivity, and file access.
In addition to these common tasks, the class library includes types that support a variety of specialized development scenarios. For example, you can use the .NET Framework to develop the following types of applications and services:
Console applications.
Windows GUI applications (Windows Forms).
ASP.NET applications.
XML Web services.
Windows services.
For example, the Windows Forms classes are a comprehensive set of reusable types that vastly simplify Windows GUI development. If you write an AP.NET Web Form application, you ca use the Web Forms classes.
2.5 Client Application Development
Client applications are the closest to a traditional style of application in Windows-based programming. These are the types of applications that display windows or forms on the desktop, enabling a user to perform a task. Client applications include applications such as word processors and spreadsheets, as well as custom business applications such as data-entry tools, reporting tools, and so on. Client applications usually employ windows, menus, buttons, and other GUI elements, and they likely access local resources such as the file system and peripherals such as printers.
Another kind of client application is the tradition ActiveX control (now replaced by the managed Window Forms control) deployed over the Internet as a Web page. This application is much like other client applications: it is executed natively, has access to local resources, and includes graphical elements.
In the past, developers created such applications using C? C++ in conjunction with the Microsoft Foundation Classes (MFC) or with a rapid application development (RAD) environment such as Microsoft visual Basic.
The .NET Framework incorporates aspects of these existing products into a single, consistent development environment drastically simplifies the development of client applications.
The Windows Forms classes contained in the .NET Framework are designed to be used for GUI development. You can easily create command windows, buttons, menus, toolbars, and other screen elements with the flexibility necessary to accommodate shifting business needs.
For example, the .NET Framework provides simple properties to adjust visual attributes associated with forms. In some cases underlying operating system does not support changing these attributes directly, and in these cases the .NET Framework automatically recreates the forms. This is one of many ways in which the .NET Framework integrates the developer interface, making coding simpler and more consistent.
Unlike ActiveX controls, Windows Forms controls have semi-trusted access to a user’s computer. This means that binary or natively executing code can access some of the resources on the user’s system (such as GUI elements and limited file access) without being able to access or compromise other resources. Because of code access security, many applications that once needed to be installed on a user’s system cam now are safely deployed through the Web. Your applications can implements the feature of a local application while being deployed like a Webpage.
2.6 Server Application Development
Server-side applications in the managed world are implemented through runtime hosts. Unmanaged applications host the common language runtime. Which allows your custom managed code to control the behaviour of the server. This model provides you with all the features of the common language runtime and class while gaining the performance and scalability of the server.
The following illustration shows a basic network schema with managed code running in different server environments. Servers such as IIS and SQL Server can perform standard operations while your applications logic executes through the managed code.
Server-side managed code into the highly distributed environment of the Internet.
If you have used earlier versions of ASP technology, you will immediately notice the improvements that ASP.NET and Web Forms offers. For example, you can develop Web Forms pages in any language that supports the .NET Framework. In addition, your code no longer needs to share the same file with your HTTP text (although it can continue to do so if you prefer). Web Forms pages execute in native machine language because, like another managed application, they take full advantage of the runtime. In contrast, unmanaged ASP pages are ASP.NET is the hosting environment that enables developers to use the .NET Framework to target Web-based applications. However, ASP.NET is more that just a runtime host: it is a complete architecture for developing Web sites and Internet-distributed objects using managed code. Both Web Forms and XML Web services use IIS and ASP.NET as the publishing mechanism for applications, and both have a collection of supporting in the .NET Framework.
XML Web services, an important evolution in Web based technology, are distributed, server-side application component similar to common Web sites. However, unlike Web-based applications, XML Web services components have no UI and are not targeted for browsers such as Internet Explorer and Netscape Navigator. Instead, XML Web services consists of reusable software components designed to be consumed by other applications, such as traditional client applications, Web-based applications, or even other XML Web services.
As a result, XML Web services technology is rapidly moving application developing and deployment always scripted and interpreted. ASP.Net pages are faster, more functional, and easier to develop than unmanaged ASP pages because they interact with the runtime like any managed application.
The .Net Framework also provides a collection of classes and tools to aid in development and consumption of XML Web services. XML Web services applications. XML Web services are built on standards such as SOAP (a remote procedural-call protocol), XML (an extensible data format), and WSDL (the Web services Description Language). The .NET Framework is built on these standards to promote interoperability with non-Microsoft solutions.
WHAT IS .NET
.NET “is the XML Web services platforms, a way of working that allows you to create software as a service.” It’s a Microsoft vision based on distributed computing, the dream of sharing information over the Internet, no matter what operating system, devices, or programming language you’re using.
According to our favourite software giant, this .NET plan covers five core areas, not all of which have yet been fulfilled:
Development products
Server products (such as Windows 2000/2003 and SQL Server)
Foundation services (such as Passport and Alerts)
Devices (such as the Pocket PC)
Experience (such as MSN and Office .NET)
2.7 Exploring Visual Studio .NET
If you haven’t installed and configured Visual Studio .NET, head off to Appendix I and follow the instructions. When you’re done, it‘s time to go exploring. Ready?
Launch Visual Studio .NET by selecting Start Programs Microsoft Visual Studio .NET Microsoft Visual Studio .NET.
You should be looking at a colourful start page, which replaces the rather bland New or Open pop-up of Visual Basic 6 frame. With its online links down the left-hand side, this page is intended to turn into something of a customizable developer portal.
Click on the New Project button.
This is more the sort of screen you’re used to welcoming you in VB6. It allows you to select a new sort of project to create. However, the options here are most certainly different to those we’d find in the old school.
First off, you can create projects in any of the three or four default languages. Naturally, we’re concerned with only Visual Basic here, but, even so, the available projects look confusing. Let’s explain them now.
You’ve got the Windows Application, which is the equivalent of a standard EXE from the old school. Desktop applications will never die (more about these applications) in Next is the class library. Although COM has actually gone in .NET, this is your rough equivalent to an ActiveX DLL project. Moving on, and a Windows Control Library allows you to build your own controls, a sort of ActiveX control project.
Shortly after that, you have an ASP.NET Web application that mixes all the great Web capabilities of ASP with the Visual Basic ability to drag, droop, and code. It’s a project that allows you to build fully functional; Web sites in seconds.
An ASP.NET Web service is next on the list, a project that allows you to expose your code methods or functions over your network or the Internet. Other applications can then call these chunks of code and process the results. It you’ve ever dealt with sticky-sticky Simple Object Access Protocol (SOAP) in VB6, this is the native .Net implementation.
Moving on, the Web control library allows you to build “controls” to use on Web pages. These are HTML based and have absolutely nothing to do with ActiveX. Next on the list is a console application that allows you to build a DOS-like console program, which was incredibly difficult in VB6 days. Next, the Windows service project allows you to build your own services, which in the old days would require either the purchase of a third-party plug-in or a nightmarish amount of API code.
Evert users, or those that have downloaded “extras” from the visual Studio .NET site, may also find a couple of extra project types in their list. The Smart Device Application, for example, allows you to create programs to run on devices such as the Pocket PC. And the ASP.NET Mobile Web Application project type will enable you to create your own mini Web sites that are customized for less-powerful wireless devices, from mobile phones to microwaves.
You can ignore any remaining project types as they’re empty placeholders.
Let’s begin this part of the book by creating a simple Windows while looking at a couple of development environment changes.
Select the Windows Application icon.
Change the name to “Hello.NET”.
Note the Location folder and click on Ok.
You should now be starting at your new (and rather plain) Hello.Net project. Recognize anything?
In the middle window you should have your form, which is the screen your users will see when they run your final application. To the left, you have the toolbox, which holds controls ready to add that form. (Click View Toolbox if you can’t see it.) Check out the various tabs: you’ll find a whole bundle here, many more than intrinsic few you had with VB6.
These are part of the core .Net Framework, which means that all your users will automatically have them installed. So, if you do use something like the OpenFileDialog control in your application, you won’t need to go bundling an extra DLL to ensure that it works on the client machine. It will just work. Well, hurrah for that!
You will find most of yours old favourites here too—with an occasional name change thrown in to warrant the purchase price, of course. The command Button Became Button1, for example. The Caption property of the Label turned into Text property. The Menu Editor turned into the Main Menu control. Still, nothing too serious.
Casting your eye over to the bottom right of your screen now, you will find the trusty properties window. No real differences here—some things never change. You will find that your form has a few interesting properties though, such as Opacity.
Moving upward slightly, you will see the solution Explorer, which is exactly the same as our Project Explorer expects that it can host multiple projects as part of your solution (like a Project Group). The extra tabs under the properties and solution Explorer windows allow you to use the help and explore classes in your application.
Let’s move on.
Draw a button out onto your form.
Double –click on the button to open up the code window under a new tab.
The next line, Inherits System.Wndows.Forms.Form, tell VB.NET that this class “inherits” the functionality of a form, the functionality described in the
System.Windows.Forms.Form part of the .NET Framework
The following line has a gray chunk displaying the words “Windows Form Designer generated code”. This is a collapsed mound of code, while you can view in full by clicking the little symbol to its left.
After you’re done that, you’ll probably wish you hadn’t. This is your form in the nude. It includes description of what controls you have on the form, along with their positioning and initial properties. Task, move over, playboy.
After this, we see our actual Button Click subroutine__finally, something you recognize. Or is it? First off, you have a couple of extra arguments here providing extra (and often useless) event information.
Also, in VB6, if changed the name of the Button1_Click method, it would no longer run the code behind that method when you clicked on Button1. In VB.NET, this isn’t the case: scroll to the end of the first line of Button1_Click here. See the Handles Keyword? This is what determines which methods run when an event occurs.
Anyway, it’s about time we added some code. And what simpler way to start than displaying the clicked Hello World in a message box. Not defined, right? Well, guess what? They changed that too. Type new .NET way of displaying a message box is using the “shared” Show functioning of the Message Box class.
8. Add the following code to respond to the click event of Button1: MessageBox.Show (“Hello World!”)
Actually, I’m lying. You can still use Message Box and all its related result constants, but Message Box is the now and improved way of displaying messages within Windows forms like this.
Let’s run our application now.
9. Press the F5 key or select Start from the Debug menu.
You’ll see a bunch of information fly past an “output” window as your code is compiled. Ignore it; it just means that your final EXE file is being slapped together.
Within a few seconds, your program should pop up. Yes, it has slightly different feel, and that Form icon definitely has to go. But, on the whole, it’s not all that alien, and a click of your Button control should produce the results you expect. Right? Well, that’s our first glimpse of the Visual Studio .NET interface. A speedy exploration, yes, but it should’ve answered a few of the initial questions every VB6 developer has. So, let’s recap; what differences have we seen so far? A whole bundle of new and exciting project types are now available.
We have a host of fresh intrinsic controls to play with. Most development files have a .VB extension. Form .VB files are really classes and include code that describes how the form is laid out. When your code compiles, a host of useless information spurts into the Output window. Oh, and I forgot to mention: you have pretty pastel-coloured menus, too. Now you know where all those research and development dollars went.
Server products (such as Windows 2000/2003 and SQL Server)
Foundation services (such as Passport and Alerts)
Devices (such as the Pocket PC)
Experience (such as MSN and Office .NET)
2.7 Exploring Visual Studio .NET
If you haven’t installed and configured Visual Studio .NET, head off to Appendix I and follow the instructions. When you’re done, it‘s time to go exploring. Ready?
Launch Visual Studio .NET by selecting Start Programs Microsoft Visual Studio .NET Microsoft Visual Studio .NET.
You should be looking at a colourful start page, which replaces the rather bland New or Open pop-up of Visual Basic 6 frame. With its online links down the left-hand side, this page is intended to turn into something of a customizable developer portal.
Click on the New Project button.
This is more the sort of screen you’re used to welcoming you in VB6. It allows you to select a new sort of project to create. However, the options here are most certainly different to those we’d find in the old school.
First off, you can create projects in any of the three or four default languages. Naturally, we’re concerned with only Visual Basic here, but, even so, the available projects look confusing. Let’s explain them now.
You’ve got the Windows Application, which is the equivalent of a standard EXE from the old school. Desktop applications will never die (more about these applications) in Next is the class library. Although COM has actually gone in .NET, this is your rough equivalent to an ActiveX DLL project. Moving on, and a Windows Control Library allows you to build your own controls, a sort of ActiveX control project.
Shortly after that, you have an ASP.NET Web application that mixes all the great Web capabilities of ASP with the Visual Basic ability to drag, droop, and code. It’s a project that allows you to build fully functional; Web sites in seconds.
An ASP.NET Web service is next on the list, a project that allows you to expose your code methods or functions over your network or the Internet. Other applications can then call these chunks of code and process the results. It you’ve ever dealt with sticky-sticky Simple Object Access Protocol (SOAP) in VB6, this is the native .Net implementation.
Moving on, the Web control library allows you to build “controls” to use on Web pages. These are HTML based and have absolutely nothing to do with ActiveX. Next on the list is a console application that allows you to build a DOS-like console program, which was incredibly difficult in VB6 days. Next, the Windows service project allows you to build your own services, which in the old days would require either the purchase of a third-party plug-in or a nightmarish amount of API code.
Evert users, or those that have downloaded “extras” from the visual Studio .NET site, may also find a couple of extra project types in their list. The Smart Device Application, for example, allows you to create programs to run on devices such as the Pocket PC. And the ASP.NET Mobile Web Application project type will enable you to create your own mini Web sites that are customized for less-powerful wireless devices, from mobile phones to microwaves.
You can ignore any remaining project types as they’re empty placeholders.
Let’s begin this part of the book by creating a simple Windows while looking at a couple of development environment changes.
Select the Windows Application icon.
Change the name to “Hello.NET”.
Note the Location folder and click on Ok.
You should now be starting at your new (and rather plain) Hello.Net project. Recognize anything?
In the middle window you should have your form, which is the screen your users will see when they run your final application. To the left, you have the toolbox, which holds controls ready to add that form. (Click View Toolbox if you can’t see it.) Check out the various tabs: you’ll find a whole bundle here, many more than intrinsic few you had with VB6.
These are part of the core .Net Framework, which means that all your users will automatically have them installed. So, if you do use something like the OpenFileDialog control in your application, you won’t need to go bundling an extra DLL to ensure that it works on the client machine. It will just work. Well, hurrah for that!
You will find most of yours old favourites here too—with an occasional name change thrown in to warrant the purchase price, of course. The command Button Became Button1, for example. The Caption property of the Label turned into Text property. The Menu Editor turned into the Main Menu control. Still, nothing too serious.
Casting your eye over to the bottom right of your screen now, you will find the trusty properties window. No real differences here—some things never change. You will find that your form has a few interesting properties though, such as Opacity.
Moving upward slightly, you will see the solution Explorer, which is exactly the same as our Project Explorer expects that it can host multiple projects as part of your solution (like a Project Group). The extra tabs under the properties and solution Explorer windows allow you to use the help and explore classes in your application.
Let’s move on.
Draw a button out onto your form.
Double –click on the button to open up the code window under a new tab.
The next line, Inherits System.Wndows.Forms.Form, tell VB.NET that this class “inherits” the functionality of a form, the functionality described in the
System.Windows.Forms.Form part of the .NET Framework
The following line has a gray chunk displaying the words “Windows Form Designer generated code”. This is a collapsed mound of code, while you can view in full by clicking the little symbol to its left.
After you’re done that, you’ll probably wish you hadn’t. This is your form in the nude. It includes description of what controls you have on the form, along with their positioning and initial properties. Task, move over, playboy.
After this, we see our actual Button Click subroutine__finally, something you recognize. Or is it? First off, you have a couple of extra arguments here providing extra (and often useless) event information.
Also, in VB6, if changed the name of the Button1_Click method, it would no longer run the code behind that method when you clicked on Button1. In VB.NET, this isn’t the case: scroll to the end of the first line of Button1_Click here. See the Handles Keyword? This is what determines which methods run when an event occurs.
Anyway, it’s about time we added some code. And what simpler way to start than displaying the clicked Hello World in a message box. Not defined, right? Well, guess what? They changed that too. Type new .NET way of displaying a message box is using the “shared” Show functioning of the Message Box class.
8. Add the following code to respond to the click event of Button1: MessageBox.Show (“Hello World!”)
Actually, I’m lying. You can still use Message Box and all its related result constants, but Message Box is the now and improved way of displaying messages within Windows forms like this.
Let’s run our application now.
9. Press the F5 key or select Start from the Debug menu.
You’ll see a bunch of information fly past an “output” window as your code is compiled. Ignore it; it just means that your final EXE file is being slapped together.
Within a few seconds, your program should pop up. Yes, it has slightly different feel, and that Form icon definitely has to go. But, on the whole, it’s not all that alien, and a click of your Button control should produce the results you expect. Right? Well, that’s our first glimpse of the Visual Studio .NET interface. A speedy exploration, yes, but it should’ve answered a few of the initial questions every VB6 developer has. So, let’s recap; what differences have we seen so far? A whole bundle of new and exciting project types are now available.
We have a host of fresh intrinsic controls to play with. Most development files have a .VB extension. Form .VB files are really classes and include code that describes how the form is laid out. When your code compiles, a host of useless information spurts into the Output window. Oh, and I forgot to mention: you have pretty pastel-coloured menus, too. Now you know where all those research and development dollars went.
0 comments:
Post a Comment