Creating the Startup Screen for Your Application

 <  Day Day Up  >  

Most FoxPro developers don't think about the container for their application, because it's automatic in FoxPro. It isn't in Visual Basic .NET; and in fact, we can do the same things in FoxPro that Visual Basic programmers have been doing for years . As usual, it's just a matter of setting a few properties, calling a few methods , and changing some aspects of the main menu.

The Startup Screen for Your Visual FoxPro Application

In FoxPro, there are two ways to build a Windows Forms project. You can either use _Screen (the FoxPro IDE screen) as the container for the rest of your forms, or you can designate your own top-level form by setting the ShowWindow property as follows :

0 - In Screen

1 - In Top-Level form

2 - As Top-Level form

If you use a top-level form, you have to designate the forms that run within it as ShowWindow type 1, In Top-Level form. This is called a Multiple Document Interface (MDI). The default is Single Document Interface ( SDI ) , and it's what you've been using for years. You can use either.

If your startup form is a top-level form, you have to select the Top-Level Form Menu option in the Menu Designer. You then have to load the menu inside the form by executing the following command in the form's Load event:

 

 DO MENU.MPR WITH THIS, .T. 

Finally, you have to suppress the appearance of the default _Screen that FoxPro automatically displays. You can make the first command in your application _Screen.WindowsState = 2 to minimize it, but that will still cause the screen to flicker, and it doesn't look professional. The correct way is to specify -T in the command-line invocation of your compiled FoxPro executable application, or to include a Config.VFP file containing the line SCREEN = OFF that's either compiled into your executable or specified following the command-line switch “c . Other than that, there are no other special requirements. It's actually a very crisp interface, and after mastering it, you may prefer it for your applications.

If I use _Screen as the container for my application, I also set a few other main form properties. I set _Screen.ControlBox to .F . so that users don't try to close their application by clicking on the "X" at the upper-right corner of the screen and are forced to use File, Exit from the menu for that purpose. (You can also specify ON SHUTDOWN code, which can be as simple as ON SHUTDOWN QUIT , in your MAIN program to override the default behavior.) I also use _Screen.WindowState = 2 (Maximized) to expand the main screen to fill the available screen.

The Startup Screen for Your Visual Basic .NET Application

In Visual Basic .NET, there is no equivalent to _Screen . When you create a Windows Forms project, the first form that's added is named Form1.vb , and it is assumed that you'll use it as a top-level form that is the container for the rest of your application. I generally change its name both externally (by right-clicking on its name in the Solution Explorer and selecting Rename from the context menu) and internally (by selecting the form in the Designer, then using F4 to open the Properties sheet and changing the (Name) property) to MainForm . Then I select the Solution Explorer again, click on the project to select it, right-click on the project and select Properties, and then open the Startup Object drop-down at the upper-right corner of the dialog and select MainForm.vb as the Main (see Figure 8.1).

Figure 8.1. The Visual Basic .NET equivalent of FoxPro's Set Main option in the Project menu pad.
graphics/08fig01.jpg

In this main form, I set the ControlBox property of my MainForm to False , so that the File, Exit command of the MainMenu control is tasked with closing any open forms, saving data, and closing the application.

If I use the FoxPro _Screen , I set the WindowState to 2 programmatically in MAIN.PRG . In Visual Basic .NET, I maximize the form, either in the Properties sheet or in code:

 

 _Screen.WindowState = 2 && FoxPro WindowState = FormWindowState.Maximized ' VB.NET  usually set in the Properties Sheet 

If I build my own topmost form in FoxPro, I set AutoCenter = .T . in the Properties sheet. In Visual Basic .NET, you can either use the Properties sheet or this code in MainForm.vb :

 

 StartPosition = FormStartPosition.CenterScreen 

In Visual Basic .NET, attempting to set a value for either of these form properties automatically displays the appropriate Enum the instant you type the "=" (see Figure 8.2). So, if you're writing code that someone else might use and there are several options for a property, you might want to create the appropriate Enum in order to take advantage of the way that IntelliSense works.

Figure 8.2. Maximizing the MainForm window.

graphics/08fig02.jpg


 <  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