| Topic: Static and Web Oriented Control In this lesson we will consider four projects using the following ActiveX controls.
1. Project using TreeView Control: The TreeView control is used to organise information in a hierarchial, structure. The TreeView Control allows you to place information into an outline format similar to the one we see in Windows Explorer. The figure 1 shows the type of organization which we require and this is the run mode window of our project. Drag a TreeView Control and three Command buttons in the form. Set the caption and the name property of the buttons as shown in the figure
Figure 2 Entering the Code: Open the Code window and enter the codes for the three command buttons as shown in the figure 1a. Private Sub Command1_Click() Private Sub Command2_Click() Private Sub Command3_Click() Figure 1a Running the Project: On selecting the start button from the Run menu, the run mode window aoppears. Now click the createlist button. It will first create the first level list. Then click the addfruit button. The fruits list will be added at the second level.. Then click the addveg button. The vegetables list will be added at the second level and the final window appears as shown in the figure 1. 2. Project using ProgressBar: The ProgressBar Control is used to pictorially represent the progress of a lengthy computer operation, say file copying or doing complex computations etc. An advancing rectangular bar will usually denote the progress. Drag a ProgressBar Control, a Text box and a command button and locate them in the form as shown in the figure 3.
Entering the code: Open the code window of the PictureBox and enter the code as shown in the figure 3a. Select the Start button from the Run Menu and click the start button. The run mode window shows the progress of the computation by an advancing rectangular bar and comes to a stop when the computation is over. The Text box shows the percentage of progress completed. The run mode window is shown in the figure 4. Private Sub cmdStart_Click() Figure 3a
3. Project involving Drag-Drop Operations: Many of the controls in VB-5 have a DragMode property which determines whether a control can be dragged or not with the mouse. In this project the drag property of a command button is illustrated by dragging it over a PictureBox Control. Drag a PictureBox and a commands button and position them as shown in the figure 5. Set the DragMode property of the button as 1-automatic. Open the code window of the PictureBox and enter the code as shown in the figure 5a.
Private Sub Picture1_DragOver(Source As Control, X As Single, Y As Single, State As Integer) On running the project you will notice that when the button is first dragged over the picture box, it is paintede red. When the button leaves the picture box, the picture box is painted green. If the user drops the button while it is over the picture box, the picure box is painted blue. The run mode window is shown in the figure 6.
Figure 6
The WebBrowser ActiveX control acts like an Internet Explorer and so can be used to view all html documents, Thus it becomes possible to view all web pages from within Visual Basic. Select Microsoft Internet Controls from the Component Dialog box and place them in the Toolbox. The Web Browser control appears as a globe in the tool box. Drag a Web Browser, a common dialog and a command button control in the design form. The WebBrowser will appear as empty rectangle and increase its size to the maximum extent possible. Change the Caption property of the command button as ‘browse’. The design window will look as shown in the figure7. Entering the Event Code: Open the code window by double clicking the command button and enter the code as shown in the figure 7a. Private Sub Command1_Click() Figure 7a Running the Project: Select Start from the Run Menu. Then click the command button. The Commmon dialog box will help you by displaying the file open dialog box. Browse through the folders and select a html document. In this case we have selected a html document containing a VBScript Program for printing the calender for the current month. The html document looks as in the figure 7b. The run mode window appears as in the figure 8. You will ,find that the calender is displayed for the current month. In fact you can browse any HTML document with this Web Browser. Figure 7b
|