在C#中显示WebPage

问题描述 投票:1回答:2

我想在我的C#项目的Windows窗体中显示网页:http://vhg.cmp.uea.ac.uk/tech/jas/vhg2018/WebGLAv.html

Screenshot of webpage

我在其中使用WebBrowser工具并编写此代码以在表单中显示此网页:

webBrowser1.Navigate("http://vhg.cmp.uea.ac.uk/tech/jas/vhg2018/WebGLAv.html");

但它没有显示完整的网页!

This shows like this

我该怎么办?

c# html winforms webbrowser-control
2个回答
2
投票

默认情况下,Windows窗体应用程序使用IE包装器而不保证使用最新的IE版本。阅读this article以了解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;
            }
        }

如果您的网站在最新的Internet Explorer(不兼容)中无法正常显示,您应该使用其他Web浏览器包装器,例如在您的.Net应用程序中嵌入Chromium的cefSharp。


0
投票

您可以使用谷歌SDK浏览或使用显示html内容裁判此link

© www.soinside.com 2019 - 2024. All rights reserved.