How To Change the Font Size in a WebBrowser Control That Is Hosted Inside a Visual Basic Application

Article translations Article translations
Article ID: 304103 - View products that this article applies to.
This article was previously published under Q304103
Expand all | Collapse all

SUMMARY

You can use the ExecWB method to print the content inside a WebBrowser control. In addition, you can use ExecWB to change the font size of the text that is displayed in a WebBrowser control that is embedded in Microsoft Visual Basic application. This article demonstrates how to use ExecWB in this way.

MORE INFORMATION

You can use ExecWB and pass the OLECMDID_ZOOM command as the cmdID parameter to retrieve the current value of the zoom level. Zoom level refers to the current font size of the text that Internet Explorer shows; it is equivalent to the value that is specified as Text Size on the View menu of Internet Explorer.

After you retrieve the current value of the font size, you can set it to a different value. The default value should be 2, which corresponds with Medium in the graphical user interface menu. Because the option allows both 2 levels greater and 2 levels smaller, the valid range for the zoom level is 0 through 4, in which 0 is smallest and 4 is largest. The OLECMDID_GETZOOMRANGE command returns the valid range for the font size, which should be from 0 to 4.

The following steps demonstrate how to add this functionality into your custom browser:
  1. Open a new standard EXE project in Visual Basic 6.0. Form1 is created by default.
  2. Add Microsoft Internet Controls into your component lists.
  3. Add a WebBrowser control and three command buttons to Form1, and use the default names.
  4. Copy and paste the following code in Form1:
    Private Sub Form_Load()
        WebBrowser1.Navigate "http://www.microsoft.com"
        Command1.Caption = "Get current font size"
        Command2.Caption = "Decrease font size"
        Command3.Caption = "Increase font size"
    End Sub
    
    
    Private Sub Command1_Click()
    
    Dim Z As Variant     'Z is the value to hold the zoom level.
    WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, Null, Z
    
    MsgBox "The current font size is " & Z
    
    End Sub
    
    Private Sub Command2_Click()
    
    Dim Z As Variant     'Z is the value to hold the zoom level.
    WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, Null, Z
    
    If Z > 0 Then
        Z = Z - 1
    Else
        Z = 0
    End If
    
    WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, Z, Null
    End Sub
    
    Private Sub Command3_Click()
    
    Dim Z As Variant     'Z is the value to hold the zoom level.
    WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, Null, Z
    
    If Z < 4 Then
        Z = Z + 1
    Else
        Z = 4
    End If
    
    WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, Z, Null
    End Sub
    					
  5. Run the project. After the page is loaded, you can click the command buttons to see the font size change that appears in the WebBrowser control.

REFERENCES

For more information, see the following Microsoft Web sites:
ExecWB Method
http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/methods/execwb.asp

IWebBrowser2::ExecWB Method
http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/ifaces/iwebbrowser2/execwb.asp

OLECMDID
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/hh/com/oen_a2z_22sk.asp
For additional information about changing the font size of a WebBrowser control that is hosted inside a Microsoft Visual C++ application, click the article number below to view the article in the Microsoft Knowledge Base:
156693 SAMPLE: IEZoom.exe Changes the Font Size of the WebBrowser Control
For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:
http://msdn.microsoft.com/ie/

http://support.microsoft.com/iep

Properties

Article ID: 304103 - Last Review: May 11, 2006 - Revision: 3.0
APPLIES TO
  • Microsoft Internet Explorer 4.01 Service Pack 1
  • Microsoft Internet Explorer 4.01 Service Pack 2
  • Microsoft Internet Explorer 5.0
  • Microsoft Internet Explorer 5.01
  • Microsoft Internet Explorer (Programming) 5.01 SP1
  • Microsoft Internet Explorer 5.5
Keywords: 
kbhowto kbwebbrowser KB304103
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com