somatic rev
somatic rev

Reputation: 575

Changing display font of WebBrowser control in c#?

I'm trying to change the display font of WebBrowser control.

I tried

doc.execCommand("FontName", false, "Arial");

But it seems it works for selected text.

I want exact same effect as setting font inside IE -> Internet Options -> General -> Appearance -> Fonts.

Thanks in advance.

Byoungjo

-------- Update -------------

Like Mitchell has pointed out, doing the same work as ExeWB is doing in C#.Net is the goal.

Also, changing registry is somewhat overwork for this and might need simpler solution if exists. Otherwise, I'll just say no to this FR.

Upvotes: 3

Views: 12526

Answers (4)

Mostafa Mahdieh
Mostafa Mahdieh

Reputation: 986

If you don't care about removing the selection, this might work:

web.Document.ExecCommand("SelectAll", false, "null");
web.Document.ExecCommand("FontName", false, "Arial"); // or any desired font
web.Document.ExecCommand("Unselect", false, "null");

Upvotes: 0

payetools-steve
payetools-steve

Reputation: 4010

Actually, you can call the ExecWB method, you just have to do so indirectly. I have the following code working for zooming up and down (using C# 4.0 makes it a bit easier):

    private const int OLECMDID_ZOOM = 63;
    private const int OLECMDEXECOPT_DONTPROMPTUSER = 2;

    private void SetZoom(int zoom)
    {
        dynamic obj = webBrowser1.ActiveXInstance;

        obj.ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, zoom, IntPtr.Zero);
    }

Upvotes: 3

Sheng Jiang 蒋晟
Sheng Jiang 蒋晟

Reputation: 15271

Since the setting is under HKEY_CURRENT_USER/Software/Microsoft/Internet Explorer, you should be able to override this setting by implementing IDocHostUIHandler2::GetOverrideKeyPath on your webbrowser site. Because Windows Forms made its IDocHostUIHandler implementation internal, I don't think you can implement IDocHostUIHandler2 on top of your WebBrowserSite. I guess you need to start from scratch, e.g. something like http://www.codeproject.com/KB/miscctrl/csEXWB.aspx Another possibility is to override the default css in your IDocHostUIHandler::GetHostInfo implementation.

Upvotes: 0

Mitchel Sellers
Mitchel Sellers

Reputation: 63126

Well, from the looks of this you need to use the execWB command as outlined in this Microsoft article.

Update

however with a further look at the documentation, I'm not seeing the execWB OR the execCommand method that you are currently using as options within the .NET browser control.

Therefore, you might have to futz with the actual IE settings, which more than likely are in the registry..

Upvotes: 2

Related Questions