Starting the New Windows Application Project

 <  Day Day Up  >  

To start a Visual Basic .NET project, open up the IDE and select File, New from the menu. The resulting dialog lets you pick from a wide range of project types. Unlike FoxPro, where there is only one language and one project type, in Visual Studio .NET you pick both the project type and the development language. This selection determines which namespaces are included in the project references. For example, if we pick Visual Basic Projects and click on the Windows Application project type, the Windows.Forms namespace (among others) will appear in the list of references. If we instead pick a Smart Devices project, the references for Pocket PC and Windows CE are included.

You first have to pick a name for your new project. When you create this project, Visual Studio adds a new directory under your default projects directory, which is initially Documents and Settings\ MyUserID \Visual Studio Projects\ YadaYada . I changed mine to C:\VBProjects and recommend that you do likewise. It creates both a solution (a container for several projects) and a project. As you'll see repeatedly in our examples, Visual Basic .NET assumes a different arrangement for projects than does FoxPro. In FoxPro, we build one project, and may include several class libraries. In Visual Basic .NET, each class library is usually built as its own project, and compiled as a DLL, then included as a reference in other projects that use the classes. It doesn't take long to get used to.

The newly created Visual Basic .NET Windows Application project also includes one form, named Form1.vb by default. Form1 is both the filename and an internal class name. You should change both. In this case, because it's the first form that was created, we'll use it as we used MAIN.PRG in our FoxPro project. There's no _Screen object in Visual Basic .NET, so this first form will become our background screen. Using F4, open the Properties window, and change the Name property to AppScreen . (If you open the code window for the form, you'll see that the class name in the first line has been changed to AppScreen .) Open the Solution Explorer with Ctrl+Alt+L and select Rename, and change Form1.vb to AppScreen.vb . Right-click again on the project in the Solution Explorer and select Rebuild.

NOTE

A FoxPro form would consist of two files, an SCX and an SCT.


Next, we'll need a menu. Use Ctrl+Alt+X to open the Toolbox, select Windows Forms, and drag a MainMenu control to anywhere on the AppScreen form. When selected, the MainMenu control appears in the upper-left corner of the screen. For now, it's the only control, so it will be selected automatically. Later, if you add other controls (for example, a label) to the form, the menu control will disappear when the label is selected. Click on the MainMenu control to begin building your menu.

The MainMenu control is simple and intuitive. (I believe it was ported directly from Delphi when the lead architect of Delphi was ported over to Microsoft.) As you move down and right, new text boxes appear to let you add menu selections. You should right-click on each of your menu pads and change the name to something meaningful (for example, mnuExit for the File, Exit menu pad), so that the Click code for the menu option makes sense when you read it. Add a File pad first, and below it add an Exit bar. Right-click on the File pad, select Properties, change the name to mnuExit , and then double-click on it and type in the single command End . Press F5 to compile and run the application, and you'll see that your form closes when you click on Exit.

The AppScreen Form Properties

The AppScreen form is the container for the rest of the forms in your application, so let's configure it more to our liking. Use F4 to open the Properties window and make the following property settings:

 

 StartPosition    CenterScreen FormBorderStyle  Fixed3D Text            - My First VB.NET Application 

Remember that I said that some things are harder in .NET? This is one of them: The drop-shadow trick that we used in Chapter 2, "Building Simple Applications in Visual FoxPro and Visual Basic .NET," to put a title on the screen with a "drop shadow" turns out to be unusually difficult in Visual Basic .NET because the Label control can't be transparent on a Windows form.

RANT

<rant>I'm sure it will be changed by the time this book hits the shelves , but at this moment, you can't get there from here. There is a different kind of control that allows drawing text with a shadow, but it's 15 lines of code, doesn't demonstrate inheritance, and is so complicated that it irritates me.</rant>


 <  Day Day Up  >  


Visual Fox Pro to Visual Basic.NET
Visual FoxPro to Visual Basic .NET
ISBN: 0672326493
EAN: 2147483647
Year: 2004
Pages: 130
Authors: Les Pinter

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