Exploring Visual Studio .NET

If you haven t yet 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?

  1. Launch Visual Studio .NET by selecting Start Programs Microsoft Visual Studio .NET Microsoft Visual Studio .NET.

You should be looking at a colorful start page, which replaces the rather bland New or Open pop-up of Visual Basic 6 fame. With its online links down the left-hand side, this page is intended to turn into something of a customizable developer portal.

  1. Click on the New Project button.

This is more the sort of screen you re used to welcoming you in VB6. (See Figure 1-1). 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.

click to expand
Figure 1-1: Creating our new Windows application project

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 Chapter 2). 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, drop, and code. It s a project that allows you to build fully functional Web sites in seconds. (Chapter 3 will reveal all.)

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. If you ve ever dealt with sticky-sticky Simple Object Access Protocol (SOAP) in VB6, this is the native .NET implementation. (More on this in Chapter 5.)

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 (been there, wrote the article, still getting the complaints: full instructions in Chapter 6). Next, the Windows service project allows you to build your own service, which in the old days would require either the purchase of a third-party plug-in or a nightmarish amount of API code. (Find out how to do this in Chapter 6.)

Everett 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 . (More on both of these project types in Chapter 6.)

You can ignore any remaining project types as they re simply empty placeholders.

Let s begin this part of the book by creating a simple Windows application while looking at a couple of development environment changes.

  1. Select the Windows Application icon.

  2. Change the name to Hello .NET .

  3. Note the Location folder and click on OK.

You should now be staring 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 to 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 the 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 ll just work . Well, hurrah for that!

You ll find most of your old favorites here, too ”with an occasional name change thrown in to warrant the purchase price, of course. The CommandButton became Button, for example. The Caption property of the Label turned into Text property. The Menu Editor turned into the MainMenu control. Still, nothing too serious.

Casting your eye over to the bottom right of your screen now, you ll find the trusty Properties window. No real difference here ”some things never change. You ll find that your form has a few new interesting properties though, such as Opacity .

Moving upward slightly, you ll see the Solution Explorer, which is exactly the same as our old Project Explorer except 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.

  1. Draw a button out onto your form.

  2. Double-click on the button to open up the Code window under a new tab, as shown in Figure 1-2.

    click to expand
    Figure 1-2: Our Code window

Wow! You don t remember writing that code? Hmm, me neither , actually. So where did it all just come from? Well, this is automatically generated code that describes your form. Let s explain it away, line by line.

First off, glance across to the Solution Explorer. Your form file is called Form1.vb ”there s no .frm extension here. Most Visual Basic .NET code files end with a .VB extension. It s the content inside that describes what they are.

This explains why our form starts off with Public Class Form1 and finishes with End Class . Yes, our form is really a class: in VB6, we could treat forms as though they were classes, but they weren t really . In VB .NET, they are. In fact, apart from primitive data types such as a Boolean or Integer, everything we use in VB .NET is based on a class ”even strings and controls.

The next line, Inherits System.Windows.Forms.Form , tells 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. (More on this later.)

The following line has a gray chunk displaying the words Windows Form Designer generated code . This is a collapsed mound of code, which you can view in full by clicking the little + symbol to its left.

After you ve done that, you ll probably wish you hadn t. This is your form in the nude. It includes descriptions of what controls you have on the form, along with their positioning and initial properties. Tsk, move over, Playboy .


You can automatically make regions of your code collapsible by adding #Region and #End Region keywords around the code.

After this, we see our actual Button1_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 you 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 clich d Hello World in a message box. Not difficult, right? Well, guess what? They changed that too. The new .NET way of displaying a message box is using the shared Show function of the MessageBox class.

  1. Add the following code to respond to the click event of Button1:

     MessageBox.Show("Hello World!") 

Actually, I m lying. You can still use MsgBox and all its related result constants, but MessageBox is the new and improved way of displaying messages within Windows forms like this.


Notice how your code is automatically formatted? Just write it, and VB .NET will position it for you. It ll also complete If statements and property declarations for you.


If you make a coding error in VB .NET, it doesn t wait until you compile your application to point it out: it s immediately highlighted via a Word-style squiggly underline. Hovering your mouse cursor over the region displays a description of the problem.

Let s run our application now.

  1. 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 a 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? Ace.

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-colored menus , too. (See Figure 1-3.) Now you know where all those research and development dollars went.

click to expand
Figure 1-3: Pick a menu option, any menu option.

If you re wondering how to compile and distribute your .NET applications, we ll look at the topic in Chapters 2 and 3. We ll also figure out how to upgrade existing applications over in Chapter 7.

So, we ve briefly explored creating a simple Windows application in VB .NET. Yes, it s a shift from VB6, but mind blowing it ain t.

But that s not all. One of the most powerful areas of .NET is its ability to serve up highly interactive Web sites with just a few lines of code. We ll take a quick look at this important project type next.

The Ultimate VB .NET and ASP.NET Code Book
The Ultimate VB .NET and ASP.NET Code Book
ISBN: 1590591062
EAN: 2147483647
Year: 2003
Pages: 76
Authors: Karl Moore

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net