Home » Microsoft Technologies

How to set font size programmatically (VB or C#) in WebBrowser control or zoom WebBrowser control

How to set font size programmatically (VB or C#) in WebBrowser control or zoom WebBrowser control

3 Answers Found


Answer 1

You would need to modify the content.  Something like this:
            webBrowser1.DocumentText = "<div style=\"font-size:6px;font-name:Verdana;color:Black;\">I'm small text</div><div style=\"font-size:17px;\">I'm not small text</div>";



Answer 2

Hi Dyma,

To change the style of an HtmlElement, we can set  its style property or modify its OutHtml content. The code snippet below shows the details of what I mean:

//Change the font  sizeprivatevoid SetFontSizeTutorial()
   //Set the body font

   //Set the font of a button named button1

  privatevoid SetFontSize(HtmlElement element)
   element.Style = "font-size:6px;";

   //Another method which is more flexible to change the html content of an element//element.OuterHtml = string.Format("<div style=\"font-size:6px;\">{0}</div>", element.OuterHtml);

  //Zoom the WebBrowserprivatevoid ZoomWebBrowser(float factor)
   string factorStr = (factor * 100).ToString() + "%";
   this.webBrowser1.Document.Body.Style += ";zoom:" + factorStr;

Let me know if this helps or not.
Aland Li

MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com

Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.

Answer 3

Hi Dyma,

Please unmark my reply and post here if my reply cannot resolve your issue.

Aland Li

MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com




is there any way to get the font size of the currently selected text in the Microsoft WebBrowser control (MSHTML)?

I am aware of

  IHTMLDocument2::queryCommandState("FontSize", ...)

but this method only returns a value between 1 and 7, for the outdated font sizes "xx-small" to "xx-large". For font sizes like "10pt" or "14px", no useful value is returned.

Is there a more flexible way to determine the font size?

- Frank

how to make bigger tabpage page headers without changing tabpage or its contents font size. i just need to change tabpage header to make it look bigger with different font. need help please.



I'm hosting a webbrowser control and loading a URL that contains a a small form that is embedded in the larger web page content. After the page is loaded, I'm modifying the html/css in memory to deleted various html elements (mostly divs) that surround the embedded form div so that the end result is all you see in the browser is the sub form.

Problem I'm having is that i want to resize the webbrowser control to fix the displayed content so I can then center webbrowser control in the C# form. I can't figure how to do this.

I tried stuff like:

	webBrowser1.Height = webBrowser1.Document.Body.OffsetRectangle.Height;
webBrowser1.Width = webBrowser1.Document.Body.OffsetRectangle.Width;

But the browser continues to display scrollbars. I'm not that far off but enough to cause the scroll bars to appear. I new to working with the webbrowser and don't really understand how the cumulative sizing of all the nested elements works and how these correspond to the browser control size.



I'm writing a couple of custom controls in VB.Net 3.5, in VS2008, and would like to resize the font size based on the height of the control, and vice-versa. Is there any way of converting a font of say 38.25pts into a me.height, or the other way round?

I realise the font width will change dependent on the font used (which isn't an issue for my purposes), but as far as I know, the font height is usually consistent!

Accessibility/Large font settings won't be an issue with this application.

Thanks in advance



I have surface enabled the WPF ChromiumBrowser.WebBrowser to have it work on the SurfaceTable, now I am trying to add functionality to allow the user to zoom the browser like IE zooming works - Any help would be much appreciated - I did wrap it in a SurfaceScrollViewer, but it is not working so smoothly - any suugestion?




Just finished a try on using webBrowser control to display a google map.

here the problems :

1. It wont zoom to see a clear view.  By this I mean it wont zoom  more than the level that the map is displaying.

Example, when the map is fetched, this is the level I see. No more than this level.

Is there something I need to do?

 2. It wont pan


3. Just ask for confirmation

Do I need to escape this &  ?       " &Lat = ...."

So far I did not escape this. Is this the correct way in WP7 Platform?








We're using Team System 2008, IE8.  When you hover over Font and Font Size, it doesn't highlight like it's enabled.  When you hover over Font Color and Background, it does highlight it, like it'll dropdown, but when you click on it, nothing happens.

I have a C# application that creates an Excel spreadsheet.  The entire sheet uses the default font "Calibri".  If I want to set the font of a particular range of cells to "Times New Roman" or "Wingdings 2", how do I accomplish this?

myRange.Font = ???????

Is it possible to set the defaul text format in CRM4 email - we have a company Standard for email format etc, including signatures, but CRM defaults to Taloma 10 pitch?  I would have thought this would have been easy to do, but i see no options settings for Font Face, Sizes etc


I’m specifying a row height and a font size (snippets of both below) for a table.  I made a presentation with what I wanted and then used the reflector to get the information I needed.


A.TableRow lTableRow = new A.TableRow(){ Height = 266700L };


A.LatinFont lLatinFont = new A.LatinFont() {Typeface = 1400, CharacterSet = 0 };

A.ComplexScriptFont lComplexScriptFont = new A.ComplexScriptFont() { Typeface = 1400, CharacterSet = 0 };


I need to be able to set these so I can ‘try’ to keep track of what I am adding on the slide so I do not overflow the rows.  But when the document opens, what I set is gone and the rows overflow.  The row height is now set to 342900L (for font 18 ??) and the font size is set to 14+ (what does this mean??)

When I select the rows and set the font size to ‘14’, the row heights update to the correct height and my overflows are gone.  I know I need to worry about word wrapping but I would like to get this first part working correctly.


Can someone let me know what I need to do in order to get the slide to open with the row height and font size I set?  Please let me know if more information is needed. 



Hi everybody!
How is it possible to set a fixed sized font on a printer using POS for .NET?
I understand that i can query the available fonts like this:
printer.DeviceEnabled = true;
// printer.FontTypefaceList returns something
How to proceed after getting the available fonts to set a fixed sized (if one is supported)?
In here it states "The application selects a font or font for a printer station by using the font font selection escape sequence (ESC|#fT)"...but where and how exactly !!?? (i need a code sample).

Thanks in advance!

I'm having trouble using the WebBrowser control in a Windows Form. I need to open a page with it (which I can do) and then progress to a series of pages with links from the first one (which I can't do very well) in order to gather information by searching the page for text and certain elements.

At present, the program runs a function to scan the first page and has trouble finding the HtmlDocument object from the WebBrowser (ie it raises an exception, saying the HtmlDocument is null). I have managed to solve the problem by raising a MessageBox straight after the WebBrowser.Navigate method is run. As soon as a MessageBox is raised the ReadyState of the WebBrowser moves from 'Uninitialized' to a latter state.

Unfortunately, using this option would require me to sit at my computer and watch the program in order to press Ok on the MessageBox dialogs for every page that is visited and looked at. Thus undermining the point of automatically searching a series of pages. I've tried solving this problem using the DocumentCompleted event, however this causes another problem which is that the event gets fired twice (despite only adding the event function only once).

Does anyone know how to wait until the WebBrowser is completely done loading the page before proceeding? Preferably by doing it programmatically from a function outside of the WebBrowser event functions. I've tried using BeginInvoke and EndInvoke, as well as WaitOne though the IAsyncResult object. Unfortunately neither seems to work.



there is an other similar post http://social.msdn.microsoft.com/Forums/en-US/vsautotest/thread/c1c08a0e-e2f7-4d5f-a0f4-a54ef22b2b0c but it is asking about web controls so I decided to make my own since it is kind of different.

I have some win controls, buttons and labels, and what I want to do is to run a test and verify that the size of the text on the controls is correct.

Is there some way to do this with coded UI tests? using the getProperty() method or something?





I tried to display a simple html in a webbrowser control in wp7, but it does not render the contents in the correct size - it shows up too small. Here is the code I tried:(I have removed unnecessary parts)

<phone:PhoneApplicationPage x:Name="phoneApplicationPage" 

 <phone:WebBrowser x:Name="Browser1" IsScriptEnabled="True" Height="200"></phone:WebBrowser></phone:PhoneApplicationPage>



where testHtml is:

publicconststring testHtml = @"
<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">
<title>300x50 Test</title></head>
<style type=""text/css"">
	width: 300px; 
	height: 50px; 
	background-color: blue;
font-family: Georgia, serif; 
color: white; 
text-align: center; 
font-size: 24px;
<div id=""box""> 
<div class='font'>300x50</div>

Any help is appreciated.



Using IE 7 & 8 on MS Windows XP Professional SP3, I need to supply buttons on a page to allow the user to zoom 
in or out (I know they could simply user the browser to do this but......... 
it’s a long story!!)  Experimenting with ways to achieve this, I am having 
difficulty achieving the same level of functionality when programmatically 
applying a zoom as appears available using the browser menu.
On the very basic webpage below, if I use ctrl (+/-) to zoom the page, the 
page content is resized correctly and everything if fine; However, if I apply 
a zoom level by setting the .style.zoom property programmatically when 
pressing the "Go" button, the zoom occurs but the contained paragraph is not 
resized meaning that the text is now off the page and, despite setting the 
overflow property to "auto" no scrollbar is present.
Am I omitting a step somewhere?  Any help would be much appreciated!!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- DW6 -->
<!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

function zoomIE()
	var content = document.getElementById("content");
	document.body.style.zoom = "1.2";
	document.body.style.overflow = "auto";
	content.style.overflow = "auto";

<div id="content">
   <h2 id="pageName">Zoom</h2>
   <input name="goButton" type="button" value="go" onclick="zoomIE();" />
    <h3>Feature Title </h3>
    <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec 
molestie. Sed aliquam sem ut arcu. Phasellus sollicitudin. Vestibulum 
condimentum facilisis nulla. In hac habitasse platea dictumst. Nulla nonummy. 
Cras quis libero. Cras venenatis. Aliquam posuere lobortis pede. Nullam 
fringilla urna id leo. Praesent aliquet pretium erat. Praesent non odio. 
Pellentesque a magna a mauris vulputate lacinia. Aenean viverra. Class aptent 
taciti sociosqu ad litora torquent per conubia nostra, per inceptos 
hymenaeos. Aliquam lacus. Mauris magna eros, semper a, tempor et, rutrum et, 
tortor. </p>
<br />


Hi All,

I want to calculate the total data sent/recieved by a webpage in web browser control. Please suggest me the best method to do this.



Whenever I need to edit the font in a textbox, the font name and font size dropdown lists are greyed out.  I have to change the font from the properties window.  Why is that?

Screenshot can be found here:



Why is it that when I am using a Windows Forms designer, and I choose a size for a font it often comes out to a fractional amount with a .25 or .75 after it, but if I type in the size manually, it does not.

For example, if I change the font for a label control to Arial 11 using the dialog (clicking the ... button in the property manager), then the font actually shows up in the designer as Arial 11.25pt

Arial 12 shows up as Arial 12pt

And Arial 16 shows up as Arial 15.75pt.

But if I manually enter the point size by typing it in without going to the font dialog, it comes out to a nice round number with no fractional part.

What's up with the weird fractional parts coming from the Font chooser dialog?

How to set the font, font size, font color in a AutoComplete textbox dropdown. I mean the DROPDOWN menu but not the textbox itself. Thanks

VB.Net :

I want to set the column header font to bold for just the column that is sorted.  Is there a way to address a specific DGV Column Header Cell as opposed to the entire Header Row?


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure