| Topic: Projects using Multiple Forms In this lesson we will consider a project using four forms. In VB, the Form is the container for all the controls that make up the user interface. A form has a title bar , on which the form’s caption is displayed. On the right side of the title bar are three buttons-Maximize, Minimize and Close. Each form is designed to operate independently of the others, and they can communicate via global variables. In other situations one form can be controlled from within another. This means you can manipulate the properties of the controls in one form, from within another form. But you cannot capture the events of one form’s controls in another form. Creating Forms: When you open the Standard Exe window, you get the first form entitled as form1. For adding a form select ‘Add Form’ from the Project menu and then select the Form icon from the Add Form Dialog Window. The second form is added, entitled as form2. In a similar manner you can add any number of forms. When the project is finally saved, you will be presented with form save dialog for each form. You can give appropriate names for each of the forms. Of course when the project is subsequently opened, all the forms in the project are automatically opened and also saved when the project is saved. Description of the Forms: The first form called the main form contains the titles of the other projects to which one can branch by clicking the appropriate button. The layout of the main form (main.frm) is as shown in the figure 1. It contains a menu bar with two titles, ‘File’ and ‘Options’. The File Menu has only one item namely, ‘Exit’. The Options menu has 3 items namely, ‘Test Buttons’, Check Box’, and ‘Option Buttons’.. It has 4 command buttons with their captions changed to ‘Test Buttons’, ‘Check Box’, ‘Option Button’ and ‘Exit’ respectively. The codes of the controls used in the main form are entered as shown in the figure 1a.
Private Sub Form_Load() Private Sub mnuButtons_Click() Private Sub mnuCheck_Click() Private Sub mnuFileExit_Click() Private Sub mnuOption_Click() Figure 1a The second form is buttons.frm. It contains an image box, two command buttons and a label. The picture property of the image box is associated with a traffic icon which comes along with Windows 95. The traffic icon contains three circles filled with red, green and amber colors respy. By clicking the change button or any one of the colored circles, one colored circle can be highlighted. The controls are arranged as shown in the figure 2 and the codes are entered as in the figure 2a in the code window of the buttons form. Private Sub imgGreen_Click() Private Sub imgRed_Click() Private Sub imgYellow_Click() Figure 2a The third form is check.frm. It contains a frame containing two option buttons, three independent option buttons, two labels and one command button. The captions are given as in the figure 3 and positioned. The code window for this form is opened and the codes are entered as shown in the figure 3a. ' set up two string variables to hold the captions Sub DisplayCaption() Private Sub cmdClose_Click() Private Sub Form_Load() Private Sub opt486_Click() Private Sub opt586_Click() Private Sub opt686_Click() Private Sub optWin95_Click() Private Sub optWinNT_Click() Figure 3a The fourth form is check.frm. It contains two check boxes, one text box and two command buttons and one label. They are captioned and positioned as shown in the figure 4. The codes are entered in the code window as shown in the figure 4a. Private Sub chkItalic_Click() Private Sub cmdClose_Click() Figure 4a
|