none
WebBrowser Point Zoom RRS feed

  • Question

  • Hello, im using click.point to click in webbrowser control.

    I've added zoom out (i need it for i can see all elements) my problem is if i keep the zoom at 100 works fine if i put zoom to 25 dont work.

    Zoom code:

        Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As EventArgs) Handles WebBrowser1.DocumentCompleted
            Try
                Dim Res As Object = Nothing
                Dim MyWeb As Object
                MyWeb = Me.WebBrowser1.ActiveXInstance
                MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, ExecOpt.OLECMDEXECOPT_DONTPROMPTUSER, 25, IntPtr.Zero)
            Catch ex As Exception
                MsgBox("Error:" & ex.Message)
            End Try
        End Sub

    Im getting point position with this:

        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            Dim WebLoc As Point = PointToScreen(WebBrowser1.Location)
            Dim WebCurPos As Point = New Point(Cursor.Position.X - WebLoc.X, Cursor.Position.Y - WebLoc.Y)
    
            With WebCurPos
                If .X < 0 Or .Y < 0 Or .X > WebBrowser1.Width Or .Y > WebBrowser1.Height Then
                    'Debug.WriteLine("Mouse position outside of webbrowser!")
                Else
                    Label1.Text = (WebCurPos.ToString)
                End If
            End With
        End Sub

    If i use zoom code to reduce to 25 the click not work if i use it with 100 works.

    I think i need to divide my code of getting point but i dont know how.

    Friday, March 3, 2017 8:56 PM

Answers

  • Hi extream87,

    Based on your description, I try to do a simple sample that keep the zoom at 100 or 25, it works fine. Here is my code sample, please refer to:

    Private 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
    
    
        Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    
            Try
    
                Dim Res As Object = Nothing
    
                Dim MyWeb As Object
    
                MyWeb = Me.WebBrowser1.ActiveXInstance
    
                MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM,
    
              execOpt.OLECMDEXECOPT_DONTPROMPTUSER, 25, IntPtr.Zero)
    
            Catch ex As Exception
    
                MsgBox("Error:" & ex.Message)
    
            End Try
    
    
        End Sub
    
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            WebBrowser1.Navigate("www.google.com")
    
    
    End Sub
    

    If you still encounter the same issue, please provide more detailed error info so that I can help you to analyze problem better.

    In addition to, I find NumericUpDown Class property are very help to zoom.

    Best Regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by extream87 Wednesday, March 8, 2017 2:30 PM
    Tuesday, March 7, 2017 7:47 AM
    Moderator