How to Zoom In and Out in WebBrowser using VB.Net

This Tutorial is all about How to Zoom In and Out in WebBrowser using VB.Net. In this tutorial you will be able to Zoom In and Out in WebBrowser using VB.Net. So lets get Started:

  • First is open the Visual Basic, Select File on the menu, then click New and create a new project.

  • Then a New Project Dialog will appear. You can rename your project, depending on what you like to name it. After that click OK

  • After that, design your form like this just like what I’ve shown you below.
    Add a Webbrowser and Button to the form.
  • Then add this following declarations.
    [vbnet]
    Dim InitialZoom As Integer = 100
    Public Enum Exec
    OLECMDID_OPTICAL_ZOOM = 63
    End Enum
    Private Enum execOpt
    OLECMDEXECOPT_DODEFAULT = 0
    OLECMDEXECOPT_PROMPTUSER = 1
    OLECMDEXECOPT_DONTPROMPTUSER = 2
    OLECMDEXECOPT_SHOWHELP = 3
    End Enum
    [/vbnet]
  • Then add this code to the Form Load Event.
    [vbnet]
    WebBrowser1.Navigate(“http://www.google.com”)
    [/vbnet]
  • Add this code to the after that, This will handle the zooming.
    [vbnet]
    Public Sub PerformZoom(ByVal Value As Integer)
    Try
    Dim Res As Object = Nothing
    Dim MyWeb As Object
    MyWeb = Me.WebBrowser1.ActiveXInstance
    MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, execOpt.OLECMDEXECOPT_PROMPTUSER, CObj(Value), CObj(IntPtr.Zero))
    Catch ex As Exception
    MsgBox(ex.Message)
    End Try
    End Sub
    [/vbnet]
  • Add this code to the Zoom in Button.
    [vbnet]
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    InitialZoom += 10
    PerformZoom(InitialZoom)
    End Sub
    [/vbnet]
  • Add this code to the Zoom out Button.
    [vbnet]
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    InitialZoom -= 10
    PerformZoom(InitialZoom)
    End Sub
    [/vbnet]
  • Finally, Click F5 to run Program

OUTPUT:

ZOOM INZOOM OUT

If you have any comments or suggestions about on How to Zoom In and Out in WebBrowser using VB.Net, please feel free to contact our webpage.

Download How to Zoom In and Out in WebBrowser using VB.Net Here

Other Articles Readers might read:

2 thoughts on “How to Zoom In and Out in WebBrowser using VB.Net”

  1. This is great – thank you. One question, the line ‘ MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, execOpt.OLECMDEXECOPT_PROMPTUSER, CObj(Value), CObj(IntPtr.Zero))’
    causes an ‘Option Strict On disallows late binding’ error. I’d rather leave Strict On so how do I fix this?

Leave a Comment