Changing display font of WebBrowser control in c#?
Solution 1
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..
Solution 2
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);
}
Comments
-
somatic rev almost 2 years
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.
-
somatic rev over 14 yearsYes, modifying the registry is only solution I've found from the web so far. But, another intention is not to change IE's default settings. Understandably, I don't want my application to change user's IE display settings.
-
Mitchel Sellers over 14 yearsWell, a more 'Tricky' way would be to inject an embedded stylesheet to every page before it renders. otherwise, since the WebBrowser is just IE inside, the settings would need to be changed at a higher level.
-
somatic rev over 14 yearsEmbedded stylesheet sounds good solution, but when I try this: IHTMLStyleSheet styleSheet = doc.createStyleSheet("", 0); styleSheet.cssText = "BODY {font-family:\"Arial\"}"; It gets 'Error HRESULT E_FAIL has been returned from a call to COM component'. A little more help on this?
-
somatic rev over 14 yearsI chose to follow Mitchel's suggestion. However thanks for the answer.
-
somatic rev almost 14 yearsAlthough this has been out of functional requirement for now, your suggestion sounds good solution for controlling browser object. Thanks.