1 / 22

CVEV 118/698 Visual Basic

CVEV 118/698 Visual Basic. Lecture 3. Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar. VB Multiple Form Support. VB allows your program to support multiple forms. To add a new form, go to the Project Menu and Select Add Form .

lcarrier
Download Presentation

CVEV 118/698 Visual Basic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CVEV 118/698 Visual Basic Lecture 3 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

  2. VB Multiple Form Support • VB allows your program to support multiple forms. • To add a new form, go to the Project Menu and Select Add Form. • Each new form will be added in Project Explorer Window.

  3. Project Properties • From Project select ProjectName Properties; or right click on the top line of the Project Explorer. • Specify Type/Name/Startup Object, I.e. which of the project’s forms should appear first at startup.

  4. Loading Forms • Some forms need not to be displayed. They can contain procedures needed to be done in the background without showing it to the user. • If a form contains data that need time to be loaded, you can load the form, then show it. The user would not feel that it took time to show the form. Load FormName Unload FormName • Warning: when a Form is loaded, it takes up resources from the system, accordingly you must unload all forms that are not needed.

  5. Showing Forms • Show method is used to display a form. FormName.Show mode • When several forms are shown, and you want the user to proceed with some information on a particular one before taking any other action, use the modality property. This option is specified through the mode argument of the Show command: Example: frmFirst.Show 0 frmSecond.Show 1 • 0 (default): Modeless. • 1: Modal, the Form takes control of the application and won’t let it proceed unless the Form is closed.

  6. Form States • Not loaded: The form exists on a disk file and doesn’t take any resources. • Loaded but not shown: The form is loaded into memory, and is ready to be displayed. • Loaded and shown: The form is shown and the user can interact with it. Several forms may be shown at the same time. • Note: when a form is unloaded and then reloaded, there is a re-initialization of properties and variables declared in it. I.e. variable values are lost. This is not the case if a form is just made invisible, and then visible again.

  7. Control Visibility Option Explicit Private Sub btnShowFirst_Click() FormFirst.Visible = True FormSecond.Visible = False End Sub Option Explicit Private Sub btnShowSecond_Click() FormSecond.Visible = True FormFirst.Visible = False End Sub

  8. Controlling a Form from Within Another • When a form is loaded but invisible, it can still be manipulated. Accessing any control of this form (such as a TextBox) is done in the following manner: FormName.ControlName.Command ex: Form1.txtGreeting.Text = “Hello”

  9. Menu Design • Menus are an important feature of Windows. They usually contain a large number of commands and options specific to the application in use. • Menus can be attached only to forms. • In VB, they are designed with the Menu Editor from the tools menu: Tools > Menu Editor

  10. Menu Editor Shortcut: Run the command when pressed, without entering the menu. e.g. Ctrl+C. Caption: String that appears on the application menu bar. Options: Controls how the commands will appear in the applications. Name: Name to be used when coding. Contents: This window shows the commands available in this menu bar.

  11. Options and Features of Menu Editor • Index: used to make a menu item part of a control array. This is helpful in making dynamic changes in the menu at runtime. • WindowList: used when you have MDI (Multiple Document Interface) windows. • Checked, Enabled, Visible: same commands as for other regular controls.

  12. Menu: Results Option: enabled and visible. Option: visible. Option: enabled, visible and checked.

  13. VB Controls

  14. ListBox & ComboBox • ListBoxes and ComboBoxes are used when dealing with a series of items, whether for simple display or for selection.

  15. ListBox & ComboBox Example ComboBox ListBox

  16. ListBox & ComboBox Basic Properties • MultiSelect: Defines if the user can select multiple item at a time, and the method of selection used. • Sorted: The items in the list are automatically sorted by the program. • Style: Controls the appearance of the control.

  17. ListBox & ComboBox Basic Methods • Add Item: Adds item to the list. List1.AddItem item, index item is the string to be added index is the column where the item should be added in the list (if “sorted” is selected, this argument is neglected) Ex: lstGreetings.AddItem “hello”, 0 • Remove Item: Removes an item from the list lstGreetings.RemoveItem index index = order of the item to be removed • Clear: Removes all items from the control. lstGreetings.Clear

  18. ListBox & ComboBox Manipulation • ListCount: Number of items inside the list. List1.ListCount (Generally useful in loops) • List(): Array holding the list items List1.List(0) = “Hi” • ListIndex: Index of the selected item in the list. If List1.ListIndex > 0 Then … • Selected: Array similar to List() but with elements that have a True or False value (if selected or not). If ( List1.Selected(counter) ) Then… • SelCount: Number of selected item.

  19. Common Dialogs • A tedious but common task in nearly every application is to prompt the user for filenames, font names and sizes, colors, etc. • All Windows applications use standard dialog boxes for common operations such as selecting a file name. These dialogs are built into the Windows operating system. • Common dialogs such as: Open, Save As, Color, Font, Print, Help are provided. All what you need to do is to set the flags properties.

  20. Common Dialogs (cont’d)

  21. Common Dialogs (cont’d) • Probably you will have to add the common dialog boxes to your toolbox: go to Project  Components  Microsoft Common Dialog Control 6.0 (SP3) • Create a Common Dialog Control on your form. • The display of a Common Dialog box is done as follows: CommonDialogName.Show**** Ex: CommonDialog1.ShowColor

  22. What’s Next • Thursday’s lab session • XO game assignment • AutoCAD VBA

More Related