7.1 Multiple Forms
-We've only dealt with using one form so far. You can use several forms within a program. The StartUp form is the one form that is automatically displayed when the program executes.
Form Files/Form Names
-Name is stored in form's Name property. When a form is created, the code associated with the form is stored in a file that has the same name followed by a .vb extension. This is in the Solutions Explorer window.
-To rename an existing form, you can do two things. If you change the form's file name within the Solution Explorer window, it'll also rename the form. However, if you just change the form name in the Name property, the form's file name doesn't change automatically.
-To add a new form to a project, click Project on the menu bar followed by Add Windows Form...
-To switch between forms during design time, double-click on the form's entry in the Solution Explorer window.
-You can designate the StartUp form in the Solution Explorer window by going to each form property.
-To remove a form/delete the file, right click/delete in Solution Explorer
-If you just want to remove a form from the current project but don't want to delete the actual file,
-right click the form in Solution Explorer/press exclude from project
-A form's class declaration (Public Class formname End Class) doesn't create a form, but is merely a blue-print.
To display a form, create an instance of the form:
-Dim ObjectVAriable As New ClassName
Example:
Dim frmError As New ErrorForm
-frmError is the variable that is declared.
-ErrorForm is the instance of the ErrorForm form that is created in memory.
NOTE: This statement doesn't cause the form to be displayed on the screen, it only creates an instance of the form in memory and assigns its address to the variable declared. You need to use the object variable to execute form methods.
Displaying a Form
-Forms can either be modal or modeless.
-Modal: when a modal form is displayed, no other form in the capplication can receive focus until this form is closed. User must close this form before they can interact with other forms.
-Modeless: allows user to switch focus to another form while it is displayed.
ShowDialog Method: causes form to be dsiplayed as a modal form.
Show Method: causes form to be displayed as a modeless form.
Examples: frmError.ShowDialog()-Modal; frmError.Show()-Modeless.
-To close a form, use the Close Method, like we've been using. Me.Close(). Causes the current executing form to close.
Hide Method: makes a form/control invisible, but it isn't removed from memory. Has same effect as setting visible property to FALSE. Use Me.Hide()
Load, Activated, FormClosing, and FormClosed Events
-Load Event: statements to be executed when the form initially loads.
-Activated Event: occurs when user switches focus to the form from another form/application.
-FormClosing Event: occurs when a form is in the process of closing, but before it has actually closed. You can use a FormClosing event handler to for instance ask the user if they really want to quit.
-FormClosed Event: occurs after a form has closed. Code to be executed immediately after a form has closed.
-To access controls on a different form, you can access them by calling them in code.
Example: Application has a form named "GreetingsForm"/on GreetingsForm there is a lbl called lblMessage.
Dim frmGreetings As New GreetingsForm
frmGreetings.lblMessage.Text="Good day!"
frmGreetings.ShowDialog()
This first creates an instance of GreetingsForm and assigns it to frmGreetings variable. the "frmGreetings." that precedes the lblMessage.Text command tells you that the form isn't the current form. The ShowDialog() will call the form's method to display the form on the screen.
Class-Level Variables
-Class level variables on one form are accessible anywhere in that form one form, but they are not accessible by default to statements outside the form file.
-To make a class-level variable available to methods outside the class, use the Public keyword.
-Remember, the AccessSpecifier is automatically set to "Public" if none is given. Remember to use the correct "Public" or "Private" keyword depending on your intention of use.
7.2 Modules
-A VB file that contains only code (procedures, functions, and declarations of variables/constants).
-These appear in the Solution Explorer when created, with a .vb extension.
-Ideal for calling the same function/procedure over several different forms.
-Format is:
Module ModuleName (this should contain "module" at the end of the name for easy reference)
[Module Conters]
End Module
-To add a module, click Project and then Add Module.
-Variables declared inside a module, but not inside a procedure/function, is a module-level variable.
-These are accessible to any procedure/function in the module.
-If "Dim" or "Private" keywords are used, the variable is not accessible to statements outside the module.
-If "Public" is used, it is accessible to statements outside the module. (known as a "global variable"
-You can add a module that you've already created to future projects by using the Project-Add Existing Item selection in the menu bar.
7.3 Menus
-Menu system: collection of commands organized in one or more drop-down menus.
-Menu designer: allows you to visually create a custom menu system for any form in an application.
See book example pg. 439 for the screenshots.
-Menu Names: each drop-down menu has a name.
-Menu Command: User selects a command by clicking it, entering access key, or shortcut key.
-Shortcut Key: key/combination of keys that cause a menu command to execute.
-Disabled menu command: cause a menu command to be disabled when you don't want user to select it.
-Checked menu command: usually one that turns an option on/off.
-Submenu:Some commands on a menu are actually names of submenus. These are characterized by a right arrow next to the command.
-Separator Bar: horizontal bar used to separate groups of commands.
MenuStrip Control
-To construct a menu, use this control.
-Everytime you add an item to a menu, you create a ToolStripMenuItem object.
-Use the Menu Designer to create menu items.
-Every ToolStripMenuItem object you create in a menu is given the same default names like all other controls and can be changed in the properties window.
Explore the properties window for all the various things you can do with menus.
-To insert a menu item above an existing menu item, start the menu designer/right-click the existing menu item/select insert and then MenuItem.
-To delete a menu item, right click the menu item to delete, select delete.
-To rearrange menu items, simply click/drag.
-You don't need to write code to display a menu/submenu. If a menu item has a menu/submenu to display, VB will display it automatically.
-If a menu item doesn't have a menu/submenu to display, use a click event handler.
7.4 Building the high Adventure Travel Agency Price Quote Application
-See book, starting pg. 451.
No comments:
Post a Comment