Link to home
Start Free TrialLog in
Avatar of gosonic
gosonic

asked on

How to determine Text Size In IE?

Using VB.net 2003 Windows forms - How do I determine which setting the user has selected for Text Size in IE. (In the IE Veiw menu where the user has the option to set Text Size to Largest, Larger, Medium,Smaller, Smallest. )

I am using  -   Dim IE As SHDocVw.InternetExplorer to obtain other properties like
IE.height, IE.LocationURL , etc,  can this info be gathered from there also or is there some other indicator I should observe to tell if  the user has changed the size of the text they view  to something other than medium/default?

IE.Document.body.currentStyle.fontsize always returns (small ) no matter the setting????

I found this example on EE  to use with the webbrowser control - can anyone help translate this over to work with IE?

Function GetFontSize(WebCtl As WebBrowser) As String
    Dim vFontSize   As Variant
   
    Call WebCtl.ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DODEFAULT, 0, vFontSize)
    Select Case vFontSize
        Case 0
            GetFontSize = "Smallest"
        Case 1
            GetFontSize = "Smaller"
        Case 2
            GetFontSize = "Medium"
        Case 3
            GetFontSize = "Larger"
        Case 4
            GetFontSize = "Largest"
    End Select
End Function


Help please
Avatar of QueueIt
QueueIt

Based on MS KB#304103 (http://support.microsoft.com/default.aspx?scid=kb;en-us;304103)

The following should work in VS2003 VB.net

        'Get current font size
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Z As Object
        IE.ExecWB(SHDocVw.OLECMDID.OLECMDID_ZOOM, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, Nothing, Z)
        MsgBox("The current font size is " & Z)
    End Sub

    Function GetFontSize(ByVal WebCtl As SHDocVw.InternetExplorer) As String
        Dim vFontSize As Object

        IE.ExecWB(SHDocVw.OLECMDID.OLECMDID_ZOOM, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, Nothing, vFontSize)
        Select Case vFontSize
            Case 0
                GetFontSize = "Smallest"
            Case 1
                GetFontSize = "Smaller"
            Case 2
                GetFontSize = "Medium"
            Case 3
                GetFontSize = "Larger"
            Case 4
                GetFontSize = "Largest"
        End Select
    End Function

        'Decrease font size
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim Z As Object
        IE.ExecWB(SHDocVw.OLECMDID.OLECMDID_ZOOM, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, Nothing, Z)
        If Z > 0 Then
            Z = Z - 1
        Else
            Z = 0
        End If
        IE.ExecWB(SHDocVw.OLECMDID.OLECMDID_ZOOM, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, Z, Nothing)
    End Sub

        'Increase font size
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim Z As Object
        IE.ExecWB(SHDocVw.OLECMDID.OLECMDID_ZOOM, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, Nothing, Z)
        If Z < 4 Then
            Z = Z + 1
        Else
            Z = 4
        End If
        IE.ExecWB(SHDocVw.OLECMDID.OLECMDID_ZOOM, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, Z, Nothing)
    End Sub

Let me know if this works for you.
ASKER CERTIFIED SOLUTION
Avatar of QueueIt
QueueIt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gosonic

ASKER

Thanks
You welcome.
Thank You.