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)?
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.
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:
Private Sub [b]Form_Load()[/b]
Call mnuTextSize_Click(2)
End Sub
Private Sub [b]mnuTextSize_Click(Index As Integer)[/b]
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.
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.
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:
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.
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.
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
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!
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?
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?
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:
Private Sub [b]Form_Load()[/b]
Call mnuTextSize_Click(2)
End Sub
Private Sub [b]mnuTextSize_Click(Index As Integer)[/b]
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.