Results 1 to 4 of 4

Thread: [2008] How to set default font for WebBrowser control?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Posts
    79

    Question [2008] How to set default font for WebBrowser control?

    Hey Guys,

    I'm displaying some text in a WebBrowser control that's not always HTML, therefore the body does not have HTML font settings in it. I'm trying to make it so that I can set the font to be displayed to be a fixed-with font, at a smaller size than it is defaulting to at the moment without any settings.

    How can I go about doing this?

    Thanks,
    JohnVM

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2008] How to set default font for WebBrowser control?

    I just played around with it and it looks like (in 2005) that the WebBrowser control uses your IE font settings.

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2008] How to set default font for WebBrowser control?

    where do you get the text that isn't html?

    Negative is right about it using IE settings, however it would be easy to simply take whatever text you want to show, and set the webbrowser controls DocumentText property.

    There are a few things to consider when doing this, like the fact that it is now not just text, but HTML, so markup applies. This gives you the ability to specify a font, but you also need to be aware of things like newlines. You would need to convert any newlines to "<br>" HTML tags... There may be others, but I would think newlines would be the most common.

    Here is a small example:

    Code:
            Dim MyString As String = "HELLO WORLD" & _
                                    Environment.NewLine & _
                                    Environment.NewLine & _
                                    "HELLO WORLD"
    
            MyString = MyString.Replace(Environment.NewLine, "<br>")
            WebBrowser1.DocumentText = "<font face=""courier new"">" & MyString & "</font>"

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Posts
    79

    Re: [2008] How to set default font for WebBrowser control?

    I'm pulling the text out of a database. And yeah, I encountered that issue regarding linebreaks.

    I ended up deciding it was too much of a PITA to use a single control and have my app use 2 controls - 1 browser and 1 textbox that are overlayed on eachother, and switch one to invisible and the other visible depending on if its html or not. Works well, and seems easier than battling WebBrowser control.

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