C# 如何使WebBrowser正确呈现网页?

C# 如何使WebBrowser正确呈现网页?,c#,C#,我被告知要在我的设置中粘贴下面堆积如山的代码,我就是这么做的。我甚至不知道它是干什么的。我只想使用C#WebView构建一个webBrowser。为什么这变得如此复杂,我如何使WebBrowser渲染页面正确。在我的webView和我的计算机上运行的internet explorer版本上,它只显示一个带有水平线的空白页。我试图显示的网页是nationalgeographic.com。请帮助 using System; using System.Windows.Forms; using Syst

我被告知要在我的设置中粘贴下面堆积如山的代码,我就是这么做的。我甚至不知道它是干什么的。我只想使用C#WebView构建一个webBrowser。为什么这变得如此复杂,我如何使WebBrowser渲染页面正确。在我的webView和我的计算机上运行的internet explorer版本上,它只显示一个带有水平线的空白页。我试图显示的网页是nationalgeographic.com。请帮助

using System;
using System.Windows.Forms;
using System.Diagnostics;
using System.Security.Permissions;
using Microsoft.Win32;

[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]

public class Program : Form

{       

private WebBrowser webBrowser;

public Program()
{
    InitialiseForm();
}

public void InitialiseForm()
{
    webBrowser = new WebBrowser();
    Controls.AddRange(new Control[] {webBrowser});
    webBrowser.ScriptErrorsSuppressed = true;
    webBrowser.Dock = DockStyle.Fill;

    webBrowser.Navigate("http://www.nationalgeographic.com/");

}

[STAThread]

public static void Main()
{
    Application.EnableVisualStyles();
    Application.Run(new Program());
}
}


}在.NET中使用的web浏览器是internet explorer,您可以从以下位置确定版本:
WebBrowser.version
,我建议使用Chromium web浏览器,它可以作为nuget软件包提供,可以用作windows窗体或WPF控件,支持html 5,优于IE,检查他们的项目并搜索C#的教程,检查此链接:

这里没有人知道如何用C sharp制作一个功能齐全的webBrowser吗?我不明白你在说什么,如果你认为是我投了你的反对票,那你就错了:)我认为这个网站上有一些反对票的机器人或是一些网络巨魔。@John你所做的只是扔掉了两段格式不好的代码,没有真正提出任何问题。StackOverflow不是一个个人编码服务,当人们读到诸如“我被告知要在我的设置中粘贴下面堆积如山的代码,我已经这样做了。我甚至不知道它做了什么”之类的东西时,它只是表明你实际上对解决你的问题没有任何兴趣,而是有人来帮你做。见:
private void Form1_Load(object sender, EventArgs e) {
        var appName = Process.GetCurrentProcess().ProcessName + ".exe";
        SetIE8KeyforWebBrowserControl(appName);
}  

private void SetIE8KeyforWebBrowserControl(string appName) {
        RegistryKey Regkey = null;
        try
        {
                // For 64 bit machine
            //if (Environment.Is64BitOperatingSystem)
                //Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);

//else  
//For 32 bit machine
        Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);


    // If the path is not correct or
    // if the user haven't priviledges to access the registry
    if (Regkey == null)
    {
        MessageBox.Show("Application Settings Failed - Address Not found");
        return;
    }

    string FindAppkey = Convert.ToString(Regkey.GetValue(appName));

    // Check if key is already present
    if (FindAppkey == "8000")
    {
        MessageBox.Show("Required Application Settings Present");
        Regkey.Close();
        return;
    }

    // If a key is not present add the key, Key value 8000 (decimal)
    if (string.IsNullOrEmpty(FindAppkey))
        Regkey.SetValue(appName, unchecked((int)0x1F40), RegistryValueKind.DWord);

    // Check for the key after adding
    FindAppkey = Convert.ToString(Regkey.GetValue(appName));

    if (FindAppkey == "8000")
        MessageBox.Show("Application Settings Applied Successfully");
    else
        MessageBox.Show("Application Settings Failed, Ref: " + FindAppkey);
}
catch (Exception ex)
{
    MessageBox.Show("Application Settings Failed");
    MessageBox.Show(ex.Message);
}
finally
{
    // Close the Registry
    if (Regkey != null)
        Regkey.Close();
}