Download presentation
Presentation is loading. Please wait.
1
CVEV 118/698 Visual Basic Lecture 3 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar
2
VB allows your program to support multiple forms. VB allows your program to support multiple forms. To add a new form, go to the Project Menu and Select Add Form. To add a new form, go to the Project Menu and Select Add Form. Each new form will be added in Project Explorer Window. Each new form will be added in Project Explorer Window. VB Multiple Form Support
3
Project Properties From Project select ProjectName Properties; or right click on the top line of the Project Explorer. 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. 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. 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. 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. 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. 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: 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. 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 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. 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. 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: 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 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. Menus can be attached only to forms. In VB, they are designed with the Menu Editor from the tools menu: In VB, they are designed with the Menu Editor from the tools menu: Tools > Menu Editor
10
Menu Editor Caption: String that appears on the application menu bar. Name: Name to be used when coding. Options: Controls how the commands will appear in the applications. Contents: This window shows the commands available in this menu bar. Shortcut: Run the command when pressed, without entering the menu. e.g. Ctrl+C.
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. 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. WindowList: used when you have MDI (Multiple Document Interface) windows. Checked, Enabled, Visible: same commands as for other regular controls. 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. ListBoxes and ComboBoxes are used when dealing with a series of items, whether for simple display or for selection. ListBoxComboBox - List appended by the program only. - Usually relatively large sized on screen. - Data accessed directly or with scrollbars. - User can also implement the list. - Usually small sized controls. - Data accessed through dropdown list.
15
ListBox & ComboBox Example ListBox ComboBox
16
ListBox & ComboBox Basic Properties MultiSelect: Defines if the user can select multiple item at a time, and the method of selection used. 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. Sorted: The items in the list are automatically sorted by the program. Style: Controls the appearance of the control. Style: Controls the appearance of the control.
17
ListBox & ComboBox Basic Methods Add Item: Adds item to the list. 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 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. Clear: Removes all items from the control. lstGreetings.Clear
18
ListBox & ComboBox Manipulation ListCount: Number of items inside the list. ListCount: Number of items inside the list. List1.ListCount (Generally useful in loops) List(): Array holding the list items List(): Array holding the list items List1.List(0) = “Hi” ListIndex: Index of the selected item in the list. 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). 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. 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. 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. 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. 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
Probably you will have to add the common dialog boxes to your toolbox: go to Project Components Microsoft Common Dialog Control 6.0 (SP3) 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. Create a Common Dialog Control on your form. The display of a Common Dialog box is done as follows: The display of a Common Dialog box is done as follows:CommonDialogName.Show**** Ex: CommonDialog1.ShowColor
22
What’s Next Thursday’s lab session Thursday’s lab session XO game assignment XO game assignment AutoCAD VBA AutoCAD VBA
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.