1. Computing

Visual Basic .NET for Beginners

What's in a Windows Forms Application?

From , former About.com Guide

When you use the Windows Forms Applicaton template for a new project, Visual Studio adds a whole hierarchy of files to your project to support the forms. Some of the files are hidden because you will never change them. But knowing about them will help you understand how Visual Basic projects work. And sometimes you might need to look a what's in them to find difficult bugs. The files that are added for a Windows Forms Application are different than the files for other templates. That's what makes the templates different.

You can see all of the files, including the hidden files, by clicking the Show All Files icon in the Solution Explorer window. The illustration below shows all of the default files for a project, as well as some things (such as References) that aren't files.

--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

Just to complete your understanding about how things work, the files and code for the project can be seen outside of Visual Studio (after the project is saved). This illustration shows The files in Windows Explorer and the default code for the Load event of a form in Notepad. You can see the code in Notepad is the same as the code in the Code Window of Visual Studio. However .... It's always a bad idea to change your program outside Visual Studio. Visual Studio keeps everything coordinated. If you change the program outside Visual Studio, for example in Notepad as shown here, you will amost always get things totally messed up.

--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

You will need to know where things are is to do things like copying the executable (the end result of programming and compiling a VB.NET program) to another location; or understand how to code the file path to other files that you might reference in your project, such as a data file that has to be opened and read. The executable for your project is in the Debug or Release Folder for the project. An executable is a ".EXE" file (a program a user can run) or a ".DLL" file (a component that can be used by other components or programs) and you can "Run" it directly from Windows. The illustration shows a default WindowsApplication1 .EXE program being run in Windows.

--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

The Form file and the Form object

You'll notice that if you add a new component to your project, such as the MonthCalendar that we added in Lesson 1, no new files are added to the project. The reason is that the code for these components is stored inside the file for the form. (Actually, most of the code is in the .NET Framework, but some local code is created to make the object unique for your project.) So, in addition to holding all of the code for the form object in your program, the form file does double duty by holding the code for a lot of the rest of your project. That's why the form "file" has a different properties window than the form "object". The illustration below shows the different properties.

--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

You can select the form file properties by selecting the form in the Solution Explorer window. Visual Studio does it's best to change the object Name to match the file Name, but if you change the Name in both places, is won't be the same. This is another reason to pick a fundamental property values, like Name, as soon as you add them and then avoid changing them. Inside the code for the form, VB.NET insists that you refer to the form object as "Me" instead of using the actual name:


Me.Location = (New System.Drawing.Point(400, 400))

(Location is a property of the form. Point is an object that we haven't learned about yet. System.Drawing is the namespace where the Point object can be found in the .NET Framework. New is a method, called the "constructor" method, of objects that is used to create a copy of the object for your program.)

Project properties

Just like the Form has it's own properties, so does the project. In fact, the project properties are extensive and can be quite technical. You can display a window for the project properties by selecting it in the Project menu or by right-clicking the Project in Solution Explorer and selecting Properties from the context menu.

The illustration below shows that there are eleven different tabs in the Project Properties window. That's a lot of properties!!

--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

A complete description of project properties is a more advanced topic.

  1. About.com
  2. Computing
  3. Visual Basic
  4. Learn VB.NET
  5. Learn VS.NET
  6. Beginning Tutorial to Learn Visual Basic .NET - 2

©2013 About.com. All rights reserved.