We have a WinForms app for the classic .NET Framework 4.7. One of the forms contains an instance of the WebBrowser control to render HTML documents. It turned out that if someone changes the Text Size option in Microsoft Help Viewer in Visual Studio
, this also affects the size of text in our WebBrowser-based viewer.
I suspect it is a global setting for the MSIE rendering engine the WebBrowser control is based on. As such, there can be other apps in which the user may change this setting and this will affect our app.
Is there a way to completely ignore this setting while rendering our HTMLs? We tried to specify explicit text sizes for the HTML tags in our HTML pages, but it seems, this does not help. It looks like the MSIE HTML renderer applies its scale factor after pages were rendered using the specified text sizes.
If it is not possible to ignore that global setting, is there an API we can use to control this Text Size parameter from our app? We could use it to provide settings like Microsoft Help Viewer does, and at least could provide the user with a similar choice list to adjust text size for comfort reading.
If possible, provide a solution in C# or VB.NET.

An example about synchronizing the WebBrowser Control's viewport scale, both Zoom and Text Size, to the settings applied by other applications (e.g., Internet Explorer or, as in this case, Help Viewer).
The Problem:
Expected Behavior:
In the sample code, a specialized class,
WebBrowserHelper, contains a method that reads from the Registry the current Zoom and FontSize settings, to update the MenuItems to the current value:The
ZoomFactorKey stores Zoom levels multiplied by1000: e.g.,150%Zoom has a value of150000,75%Zoom has a value of75000The
WebBrowserHelper'sSetZoom()method uses the WebBrowser ActiveX instance to set the Zoom level, calling its ExecWb method, passing asOLECMDIDargument theOLECMDID_OPTICAL_ZOOMvalue, theOLECMDEXECOPTargument is set toOLECMDEXECOPT_DONTPROMPTUSERand thepvaInargument (the Zoom value) is set to the Integer value of the Zoom level specified.▶ This also updates the
ZoomFactorRegistry Key.The
IEFontSizeandIEFontSizePrivateKeys store a binary value, in the rage[0-4]. These values loosely correspond to thex-small,small,medium,large,x-largeCSS settings.The
FontSizescale is applied to the Document Body, using a multiplier:[Value + 1] * 4.The
SetTextScale()method uses the WebBrowser ActiveX instance to set the FonSize scale, calling itsExecWb()method, passing asOLECMDIDargument theOLECMDID_ZOOMvalue, theOLECMDEXECOPTargument is set toOLECMDEXECOPT_DONTPROMPTUSERand thepvaInargument (the Font scale value) is set to an Integer value in the range[0, 4]as specified.▶ This also updates the
IEFontSizeRegistry Key.Another option is to reset both Zoom and FontSize to default values before a WebBrowser session is started.
You can call the
WebBrowserHelper.InternetResetZoomAndFont()method. Setting both arguments totrue, it will reset the Zoom level to100%and FontSize toMedium.▶ Here, I'm adding some ToolStripMenuItems that allow to set the Zoom value and FontSize - which is set to a pre-defined scale - as applied by Internet Explorer 11.
zoomMenuItems. All use the sameClickevent handler,zoomToolStripMenuItems_ClicktextMenuItems. All use the sameClickevent handler,textToolStripMenuItems_ClickTagproperty of each ToolStripMenuItem (you can of course use any other means to associate a value to a specific ToolStripMenuItem)browserViewSettingsAssume the WebBrowser Control is named
webBrowser1:WebBrowserHelperclass:This is how it works: