logo
vbRad Home
Source Code
Book Reviews
Forum
Links
About Us
Contribute

Compare Databases with SQL Effects Clarity
 
 Delay loading WebBrowser or any other control

Posted on
2/21/2002
Author:
Robert Gelb
Email:
Not Shown
Applies To OS:
NT, 9x, 2k, XP
Product:
6



One of the problems with using the WebBrowser control on your VB forms is that it causes a fairly large performance hit when starting the application. The same can be said for some commercial grids and other heavy-duty controls. If you need these controls on startup, there is not much that can be done. However, if you need the WebBrowser control later in the life of the application, you can delay loading the control until you actually need it.

The key here is the Form.Controls collection. Starting with VB6, you can add controls to it as you go. The only downside to this method is that you have to preselect the controls you are planning to use in Project/Components. Then, and this is the most important step, go to Project Properties, select the Make tab and uncheck the 'Remove information about unused ActiveX Controls' checkbox. There is a method to completely avoid this whole rigmarole, whereby there is no need to preselect wanted controls, but the event handling in this case is not very intuitive and very un-VB like. Ok, on to the project.

Project instructions
  • Start New Standard EXE Project
  • Press Ctrl+T, select Microsoft Internet Controls and press OK
  • Go to Project Properties, select the Make tab and uncheck the 'Remove information about unused ActiveX Controls' checkbox, click OK
  • Add a Frame control to the form. Make the Form and the Frame fairly large
  • Add a Command button control on to the form
Add the following code to form
Private WithEvents browser as SHDocVwCtl.WebBrowser

Private Sub Command1_Click()
   Set browser = Controls.Add("Shell.Explorer.2", "browser", Frame1)
   With browser
      .Visible = True
      .Width = Frame1.Width - 2000
      .Height = Frame1.Height - 2000
      .Top = 1000
      .Left = 1000
      .Navigate "http://www.yahoo.com"
   End With
End Sub

Post instructions
  • Press Command1 button to load the browser control on the fly.



Add Your Comment  

Name: Email Address: all fields optional
Notify me via email when someone responds to this message (valid email required).

Enter the word: