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

0
59

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.
    1. Dim InitialZoom As Integer = 100
    2. Public Enum Exec
    3. OLECMDID_OPTICAL_ZOOM = 63
    4. End Enum
    5. Private Enum execOpt
    6. OLECMDEXECOPT_DODEFAULT = 0
    7. OLECMDEXECOPT_PROMPTUSER = 1
    8. OLECMDEXECOPT_DONTPROMPTUSER = 2
    9. OLECMDEXECOPT_SHOWHELP = 3
    10. End Enum
  • Then add this code to the Form Load Event.
    1. WebBrowser1.Navigate("http://www.google.com")
  • Add this code to the after that, This will handle the zooming.
    1. Public Sub PerformZoom(ByVal Value As Integer)
    2. Try
    3. Dim Res As Object = Nothing
    4. Dim MyWeb As Object
    5. MyWeb = Me.WebBrowser1.ActiveXInstance
    6. MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, execOpt.OLECMDEXECOPT_PROMPTUSER, CObj(Value), CObj(IntPtr.Zero))
    7. Catch ex As Exception
    8. MsgBox(ex.Message)
    9. End Try
    10. End Sub
  • Add this code to the Zoom in Button.
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2. InitialZoom += 10
    3. PerformZoom(InitialZoom)
    4. End Sub
  • Add this code to the Zoom out Button.
    1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    2. InitialZoom -= 10
    3. PerformZoom(InitialZoom)
    4. End Sub
  • 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:

Facebook Comments
(Visited 66 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here