C# 用C语言显示网页#
我想以我的C#项目的Windows形式显示网页 我在其中使用WebBrowser工具,并编写以下代码以表格形式显示此网页:C# 用C语言显示网页#,c#,html,winforms,webbrowser-control,C#,Html,Winforms,Webbrowser Control,我想以我的C#项目的Windows形式显示网页 我在其中使用WebBrowser工具,并编写以下代码以表格形式显示此网页: webBrowser1.Navigate("http://vhg.cmp.uea.ac.uk/tech/jas/vhg2018/WebGLAv.html"); 但是它没有显示完整的网页 我应该怎么做?默认情况下,Windows窗体应用程序使用IE包装,不保证使用最新的IE版本。阅读了解IE包装背后发生的事情以及Windows仿真密钥的作用 我的一个旧项目中的这段代码允
webBrowser1.Navigate("http://vhg.cmp.uea.ac.uk/tech/jas/vhg2018/WebGLAv.html");
但是它没有显示完整的网页
我应该怎么做?默认情况下,Windows窗体应用程序使用IE包装,不保证使用最新的IE版本。阅读了解IE包装背后发生的事情以及Windows仿真密钥的作用 我的一个旧项目中的这段代码允许以编程方式更改可执行进程的默认IE仿真版本:
private static readonly string BrowserEmulationRegistryKeyPath =
@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";
/// <summary>
/// Add the process name to internet explorer emulation key
> /// i do this because the default IE wrapper dose not support the latest JS features
> /// Add process to emulation key and set a DWord value (11001) for it means we want use IE.11 as WebBrowser component
/// </summary>
public bool EmulateInternetExplorer()
{
using (
var browserEmulationKey = Registry.CurrentUser.OpenSubKey(BrowserEmulationRegistryKeyPath,
true))
{
if (browserEmulationKey == null)
Registry.CurrentUser.CreateSubKey(BrowserEmulationRegistryKeyPath);
string processName = $"{Process.GetCurrentProcess().ProcessName}.exe";
// Means emulation already added and we are ready to start
if (browserEmulationKey?.GetValue(processName) != null)
return true;
// Emulation key not exists and we must add it ( We return false because application restart to take effect of changes )
if (browserEmulationKey != null)
{
browserEmulationKey.SetValue(processName, 11001, RegistryValueKind.DWord);
browserEmulationKey.Flush();
}
return false;
}
}
私有静态只读字符串浏览器仿真注册表键路径=
@“软件\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE\u浏览器\u仿真”;
///
///将进程名称添加到internet explorer仿真密钥
>///我这样做是因为默认的IE包装不支持最新的JS功能
>///将进程添加到仿真键并为其设置DWord值(11001),这意味着我们希望使用IE.11作为WebBrowser组件
///
公共bool仿真InternetExplorer()
{
使用(
var browserEmulationKey=Registry.CurrentUser.OpenSubKey(BrowserEmulationRegistryKeyPath,
正确的)
{
如果(BrowserSimulationKey==null)
Registry.CurrentUser.CreateSubKey(BrowserEmulationRegistryKeyPath);
字符串processName=$“{Process.GetCurrentProcess().processName}.exe”;
//意味着已经添加了仿真,我们已经准备好开始了
if(BrowserSimulationKey?.GetValue(processName)!=null)
返回true;
//仿真密钥不存在,我们必须添加它(我们返回false,因为应用程序重新启动以使更改生效)
if(browserEmulationKey!=null)
{
SetValue(processName,11001,RegistryValueKind.DWord);
BrowserSimulationKey.Flush();
}
返回false;
}
}
如果您的网站未在最新的Internet Explorer中正确显示(不兼容),则应使用其他web浏览器包装器,如在.Net应用程序中嵌入Chromium的cefSharp。您可以使用google SDK浏览或使用showing html内容