• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1000
  • Last Modified:

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
0
gosonic
Asked:
gosonic
  • 3
1 Solution
 
QueueItCommented:
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.
0
 
QueueItCommented:
You'll need to change 'IE' to reflect the name of your webbrowser or 'SHDocVw.InternetExplorer' object.
This also assumes that your app has a reference to 'Microsoft Internet Controls' (c:\WINDOWS\system32\shdocvw.dll).
0
 
gosonicAuthor Commented:
Thanks
0
 
QueueItCommented:
You welcome.
Thank You.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now