The problem with the WebBrowser control is that by default it renders output in IE7 rendering mode.
Internet Explorer 7 rendering will be used if you do not override the Feature Browser Emultate setting in the registry.
Open the registry, I used the key: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
For your user (Current User) only use this key:
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
For all users on the computer/server use this key:
On 64 bit app on 64 bit- or 32 bit app on 32 bit machine: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION
On 32 bit app on 64 bit machine:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION
Value:
11001 (0x2AF9) Internet Explorer Webpages are displayed in IE11 edge mode, regardless of the !DOCTYPE directive.
My executable is named webBrowserDemo.exe, so I add an DWORD entry with the Name webBrowserDemo.exe and with a value 11001 (to use Internet Exlporer 11-rendering).
The picture of result:
You could click the download icon to download the picture successfully.
Update:
The HTML script error pops up an IE error message, which has almost no effect on the program. You could try to use the following code to hide it.
The code of xaml:
<StackPanel>
<WebBrowser x:Name="mBrowser" Source="http:\\www.baidu.com" Width="800" Height="600" />
</StackPanel>
The code of xaml.cs:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
HideScriptErrors(mBrowser,true);
}
public void HideScriptErrors(WebBrowser wb, bool hide)
{
var fiComWebBrowser = typeof(WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);
if (fiComWebBrowser == null) return;
var objComWebBrowser = fiComWebBrowser.GetValue(wb);
if (objComWebBrowser == null)
{
wb.Loaded += (o, s) => HideScriptErrors(wb, hide); //In case we are to early
return;
}
objComWebBrowser.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, objComWebBrowser, new object[] { hide });
}
}
The picture of result:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.