2017-01-23 41 views
-4
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()); 
} 

我被告知在我的设置中粘贴下面这段代码,我已经完成了。我什至不知道它做了什么。我只想使用C#WebView构建webBrowser。为什么这变得如此复杂,我该如何使WebBrowser正确呈现页面。它仅在我的webView上显示一个带有水平线的空白页面,并且也显示在我的计算机上运行的Internet Explorer版本。我想显示的网页是nationalgeographic.com.Please帮助如何使WebBrowser正确渲染WebPages?

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(); 
} 

}

}

+0

这里没有人知道如何在c sharp中制作一个功能完备的web浏览器吗? – John

回答

0

在.NET中使用的Web浏览器是Internet Explorer,并可以决定从版本:我建议使用Chromium网页浏览器,它可以作为Nuget包使用,并可以用作Windows窗体或WPF控件,并支持HTML 5,它比IE更好,检查他们的项目并搜索C#教程,查看此链接: https://github.com/cefsharp/CefSharp

+0

你在开玩笑吗? – John

+0

我不明白你在说些什么,如果你认为我是一个投反对票的人,那么你错了:) –

+0

我认为有一些downvote机器人或一些互联网巨魔on这个网站。 – John