Results 1 to 22 of 22

Thread: Text Size!

  1. #1

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Thumbs up Text Size!

    Using the WebBrowser control, how do I increase/decrease the text size of a web page (like how the text size of a web page can be altered in IE by navigating to the View menu & then selecting Text Size)?

    Thanks,

    Arpan

  2. #2
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Re: Text Size!

    Set the Body's style to include "Font-Size:xx" where xx is the new size.

    As you'll see (even with IE), explicitly sized fonts do not change when you use IE's text size. Same will happen to your's in this case.

    r0ach™
    Don't forget to rate the post

  3. #3

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Text Size!

    Set the Body's style to include "Font-Size:xx" where xx is the new size.
    But how do I set the body's style to include the font size? I mean to say that such styles are coded in HTML, ASP documents something like
    Code:
    <html>
    <body>
    <font size=3 face="Arial">
    ....................
    ....................
    ....................
    </body>
    </html>
    So how do I do the same in VB? What's should the code be & where do I put the code?

    Actually I have never done anything like this.

    Thanks,

    Arpan

  4. #4
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Re: Text Size!

    If you are using the webbrowser control in vb you can get a refference to the html document object. this object exposes a "Body" object. Under the body object, you'll find the styles property. To these styles, add "font-size:15px;", or whatever size and unit you would like to set it to.

    r0ach™
    Don't forget to rate the post

  5. #5
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Re: Text Size!

    Here's a little sample I quickly made. You'll see that the explicitly sized text remain the same.
    Attached Files Attached Files

    r0ach™
    Don't forget to rate the post

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Text Size!

    I have a full web browser that I spend a few years on, in VB6 using the WebBrowser control.

    This is the method that IE uses (and I used) to change the text size.
    VB Code:
    1. Private Sub mnuTextSize_Click(Index As Integer)
    2.     ' snip...
    3.  
    4.     brows.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(4 - Index), Null
    5.  
    6.     ' snip
    7. End Sub

    Valid indices for the "Index" parameter being:
    Code:
    0 - Largest
    1 - Larger
    2 - Medium
    3 - Smaller
    4 - Smallest
    HTH you

  7. #7
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Re: Text Size!

    cool.

    I just did it the simple way. For a quick fix...

    r0ach™
    Don't forget to rate the post

  8. #8

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Text Size!

    I have a full web browser that I spend a few years on, in VB6 using the WebBrowser control.

    This is the method that IE uses (and I used) to change the text size.
    Penagate, I tried out your code & it works fine but for a petty problem. The Text Size menu I am using is exactly the same that IE uses (under the View menu). This is how I did it:
    VB Code:
    1. Private Sub [b]Form_Load()[/b]
    2.     Call mnuTextSize_Click(2)
    3. End Sub
    4. Private Sub [b]mnuTextSize_Click(Index As Integer)[/b]
    5.     wWeb.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(4 - Index), Null
    6. End Sub
    7. Private Sub [b]mnuLargest_Click()[/b]
    8.     Call mnuTextSize_Click(0)
    9. End Sub
    10. Private Sub [b]mnuLarger_Click()[/b]
    11.     Call mnuTextSize_Click(1)
    12. End Sub
    13. Private Sub [b]mnuMedium_Click()[/b]
    14.     Call mnuTextSize_Click(2)
    15. End Sub
    16. Private Sub [b]mnuSmaller_Click()[/b]
    17.     Call mnuTextSize_Click(3)
    18. End Sub
    19. Private Sub [b]mnuSmallest_Click()[/b]
    20.     Call mnuTextSize_Click(4)
    21. End Sub
    But what happens is as soon as the mouse is over the Text Size menu item, the text size of the web page becomes Largest (note that I haven't clicked the Largest sub-menu). How do I overcome this? I want that by default, the Text Size should be Medium.

    Thanks,

    Arpan

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Text Size!

    I don't know where your "mnuTextSize" controls are if you already have "mnuSmallest" etc., but I just made the whole thing a control array. It was mnuTextSize(0 To 4) where the captions of each were as I listed above. There is no need to call anything on form_Load() because the default size is Medium anyway.

    So my menu structure was:

    Code:
    View
        ...
        Text Size
            Largest    mnuTextSize(0)
            Larger     mnuTextSize(1)
            Medium     mnuTextSize(2)
            Smaller    mnuTextSize(3)
            Smallest   mnuTextSize(4)
            -
            Increase
            Decrease
    where Increase and Decrease incremented and decremented a variable containing the current font size, respectively, and then called the mnuTextSize_Click() handler passing that variable as the Index parameter.

  10. #10

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Text Size!

    I don't know where your "mnuTextSize" controls are if you already have "mnuSmallest" etc., but I just made the whole thing a control array. It was mnuTextSize(0 To 4) where the captions of each were as I listed above. There is no need to call anything on form_Load() because the default size is Medium anyway.
    Penagate, as pointed out earlier, my menu is exactly identical to the Text Size menu item (under the View menu) in IE. Nevertheless, this is how my menu looks:
    Code:
                        View
                 ....Text Size      mnuTextSize(0)
                 ........Largest    mnuLargest
                 ........Larger     mnuLarger
                 ........Medium     mnuMedium
                 ........Smaller    mnuSmaller
                 ........Smallest   mnuSmallest
    Now what is happening is as soon as the mouse hovers over the Text Size menu, as expected, the sub-menu (Largest, Larger, Medium, Smaller & Smallest) opens up & then the text size becomes largest.

    So where am I going wrong?

    Arpan
    Last edited by arpan_de; Dec 1st, 2005 at 08:53 AM.

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Text Size!

    Oh - because when a submenu opens it fires the _Click event - because your "Text Size" menu has the index 0, it has the effect that you'd expect if you clicked "Largest". If you look at my menu structure you'll see that I named them differently, with each individual size having an index for its size. It doesn't work at all if the parent menu is part of the array. Just name the "Text Size" one mnuViewTextSize or something, and then each size is "mnuTextSize(x)" with x from 0 to 4.

  12. #12

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Text Size!

    Oh - because when a submenu opens it fires the _Click event - because your "Text Size" menu has the index 0, it has the effect that you'd expect if you clicked "Largest". If you look at my menu structure you'll see that I named them differently, with each individual size having an index for its size. It doesn't work at all if the parent menu is part of the array. Just name the "Text Size" one mnuViewTextSize or something, and then each size is "mnuTextSize(x)" with x from 0 to 4.
    Yeah Penagate, it's working now.

    One last question on this topic - I want that which is the current text size, only that size should be checked in the menu. For e.g. if the text size is smaller, then Smaller should be checked & the rest should be unchecked or if the text size is largest, then Largest should be checked & the rest should be unchecked. One way of doing this is
    VB Code:
    1. Private Sub mnuTextSize_Click(Index As Integer)
    2.     If (Index = 0) Then
    3.         mnuTextSize(0).Checked = True
    4.         mnuTextSize(1).Checked = False
    5.         mnuTextSize(2).Checked = False
    6.         mnuTextSize(3).Checked = False
    7.         mnuTextSize(4).Checked = False
    8.         ...............
    9.         ...............
    10.         ...............
    11.     End If
    12.     wWeb.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(4 - Index), Null
    13. End Sub
    But this means that there will be many If...Else statements. Any other way to do this?

    Thanks,

    Arpan

  13. #13
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Text Size!

    OK, here's the complete unsnipped source of my handler routine that I should have provided in the first place

    VB Code:
    1. Private Sub mnuTextSize_Click(Index As Integer)
    2.     For i = mnuTextSize.LBound To mnuTextSize.UBound
    3.         If Not i = Index Then
    4.             mnuTextSize(i).Checked = False
    5.           Else
    6.             mnuTextSize(i).Checked = True
    7.         End If
    8.     Next i
    9.  
    10.     brows.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(4 - Index), Null
    11.     bSearch.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(4 - Index), Null
    12.  
    13.     SetAppSetting "TextZoom", 4 - Index
    14. End Sub

    Of course, I wrote that a long time ago, and it could be simplified a bit.
    VB Code:
    1. Private Sub mnuTextSize_Click(Index As Integer)
    2.     For i = mnuTextSize.LBound To mnuTextSize.UBound
    3.         mnuTextSize(i).Checked = (i <> Index)
    4.     Next i
    5.  
    6.     brows.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(4 - Index), Null
    7.  
    8.     SetAppSetting "TextZoom", 4 - Index
    9. End Sub

  14. #14

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Text Size!

    Penagate, where from is this SetAppSetting coming? It throws an error saying Sub or Function not defined. I tried searching this forum but my search yielded only 1 result. Guess which was that? This very post! Couldn't find anything else!

    Arpan

  15. #15
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Text Size!

    Sorry about that

    Basically it just stores the value in the registry. You can accomplish the same with a module-level variable.

    VB Code:
    1. Private fontSize As Long
    2.  
    3. Private Sub Form_Load()
    4.     fontSize = 2   ' medium
    5.     ' ...
    6. End Sub
    7.  
    8. Private Sub mnuTextSize_Click(Index As Integer)
    9.     For i = mnuTextSize.LBound To mnuTextSize.UBound
    10.         mnuTextSize(i).Checked = (i <> Index)
    11.     Next i
    12.  
    13.     fontSize = (4 - Index)
    14.     brows.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, fontSize, Null
    15. End Sub

  16. #16

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Text Size!

    Penagate, sorry to say that your code throws an error saying Member already exists in a object model from which this object model derives pointing to the Private fontSize As Long line. If I delete that line, then except for medium, the rest of the text sizes get checked! What's wrong now?

    Arpan

  17. #17
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Text Size!

    Well, I have never seen that error before, but just try naming it something else - like textZoom or zoomIndex or something.

    And change the line in the For loop to this
    VB Code:
    1. mnuTextSize(i).Checked = (i = Index)

    Not my day is it

  18. #18

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Text Size!

    Not my day is it
    ......but finally I have made your day (or is it the other way round??)

    It's working now but what was the problem with fontSize? I am more inquisitive because you haven't ever encountered that error!

    Thanks,

    Arpan

  19. #19
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Text Size!

    I have honestly no idea. Was that the exact wording? Because Google turned up nothing for that phrase.

  20. #20

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Text Size!

    I have honestly no idea. Was that the exact wording?
    I reproduced the exact error message....exactly as what VB threw.

    BTW, Penagate, just now I realized that though the different sizes are getting checked/unchecked correctly but the text size always remains medium. Checking the other 4 sizes doesn't make any difference to the text size! What could be the problem now?

    Arpan

  21. #21
    New Member
    Join Date
    Apr 2006
    Posts
    2

    Re: Text Size!

    Thanks shirazamod this works perfectly!!!

    penagate, your example is exactly the same line of code I've been trying. There is something else that I probably need for it to work.

    Thanks
    Brian

  22. #22
    Member MSWindowsUser's Avatar
    Join Date
    Dec 2007
    Posts
    40

    Re: Text Size!

    Quote Originally Posted by arpan_de
    Penagate, I tried out your code & it works fine but for a petty problem. The Text Size menu I am using is exactly the same that IE uses (under the View menu). This is how I did it:
    VB Code:
    1. Private Sub [b]Form_Load()[/b]
    2.     Call mnuTextSize_Click(2)
    3. End Sub
    4. Private Sub [b]mnuTextSize_Click(Index As Integer)[/b]
    5.     wWeb.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(4 - Index), Null
    6. End Sub
    7. Private Sub [b]mnuLargest_Click()[/b]
    8.     Call mnuTextSize_Click(0)
    9. End Sub
    10. Private Sub [b]mnuLarger_Click()[/b]
    11.     Call mnuTextSize_Click(1)
    12. End Sub
    13. Private Sub [b]mnuMedium_Click()[/b]
    14.     Call mnuTextSize_Click(2)
    15. End Sub
    16. Private Sub [b]mnuSmaller_Click()[/b]
    17.     Call mnuTextSize_Click(3)
    18. End Sub
    19. Private Sub [b]mnuSmallest_Click()[/b]
    20.     Call mnuTextSize_Click(4)
    21. End Sub
    But what happens is as soon as the mouse is over the Text Size menu item, the text size of the web page becomes Largest (note that I haven't clicked the Largest sub-menu). How do I overcome this? I want that by default, the Text Size should be Medium.

    Thanks,

    Arpan
    ...&Size
    ......&Largest
    ......Lar&ger
    ......&Medium
    ......&Smaller
    ......Small&est

    mnuLargest_Click()
    WebBrowser1.Exec OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(4 - Index), Null

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width