Home » Microsoft TechnologiesRSS

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>";

 

--
Mike
 

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
   SetFontSize(webBrowser1.Document.Body);

   //Set the font of a button named button1
   SetFontSize(webBrowser1.Document.GetElementById("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.

Regards,
Aland Li

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

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter