WebBrowser控件不会在Windows 10中显示已加载的页面

时间:2017-09-22 15:21:06

标签: c# .net winforms

我有一个授权表单,用于让用户授权我的应用程序代表他们使用他们的名字,这在Windows 7中运行良好,但似乎在Windows 10中失败。我试图添加注册表项正如在其他一些问题中所建议的那样,并且还添加了'WebBrowser.AllowNavigation = true;'如果需要的话。在任何情况下,控件似乎都是有效的,因为它导航到页面并说文档已加载,但屏幕上没有显示任何内容。

    static Authorize form = new Authorize();
    static void Main2(object state)
    {
        Application.Run((Form)state);
    }
    static Authorize form = new Authorize();
    public static Authorize Create()
    {
        Thread thread = new Thread(Main2);
        thread.SetApartmentState(ApartmentState.STA);
        thread.Start(form);
        form.FormClosing += Authorize_FormClosing;
        return form;
    }
    public void InitForm()
    {
        InitializeComponent();
        this.FormClosing += Authorize_FormClosing;
    }
    public Authorize(string Url)
    {
        InitializeComponent();
        AuthCont.AllowNavigation = true;
        AuthCont.Navigate(Url);
    }
    public void NavigateTo(string Url)
    {
        AuthCont.Navigate(Url);
    }

1 个答案:

答案 0 :(得分:1)

您需要使用Windows检查浏览器版本并为您的应用添加适当的注册表项

        int BrowserVer, RegVal;

        // get the installed IE version
        using (WebBrowser Wb = new WebBrowser())
            BrowserVer = Wb.Version.Major;

        // set the appropriate IE version
        if (BrowserVer >= 11)
            RegVal = 11001;
        else if (BrowserVer == 10)
            RegVal = 10001;
        else if (BrowserVer == 9)
            RegVal = 9999;
        else if (BrowserVer == 8)
            RegVal = 8888;
        else
            RegVal = 7000;

        // set the actual key
        Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", "[your_exe_name, ex: myapp.exe]", RegVal);