Use latest version of Internet Explorer in the webbrowser control

后端 未结 13 1395
长发绾君心
长发绾君心 2020-11-21 23:29

The default version of the webbrowser control in a C# Windows Forms application is 7. I have changed to 9 by the article Browser Emulation, but how is it possible t

相关标签:
13条回答
  • 2020-11-22 00:05

    Visual Basic Version:

    Private Sub setRegisterForWebBrowser()
    
        Dim appName = Process.GetCurrentProcess().ProcessName + ".exe"
        SetIE8KeyforWebBrowserControl(appName)
    End Sub
    
    Private Sub SetIE8KeyforWebBrowserControl(appName As String)
        'ref:    http://stackoverflow.com/questions/17922308/use-latest-version-of-ie-in-webbrowser-control
        Dim Regkey As RegistryKey = Nothing
        Dim lgValue As Long = 8000
        Dim strValue As Long = lgValue.ToString()
    
        Try
    
            'For 64 bit Machine 
            If (Environment.Is64BitOperatingSystem) Then
                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)
            End If
    
    
            'If the path Is Not correct Or 
            'If user't have priviledges to access registry 
            If (Regkey Is Nothing) Then
    
                MessageBox.Show("Application Settings Failed - Address Not found")
                Return
            End If
    
    
            Dim FindAppkey As String = Convert.ToString(Regkey.GetValue(appName))
    
            'Check if key Is already present 
            If (FindAppkey = strValue) Then
    
                MessageBox.Show("Required Application Settings Present")
                Regkey.Close()
                Return
            End If
    
    
            'If key Is Not present add the key , Kev value 8000-Decimal 
            If (String.IsNullOrEmpty(FindAppkey)) Then
                ' Regkey.SetValue(appName, BitConverter.GetBytes(&H1F40), RegistryValueKind.DWord)
                Regkey.SetValue(appName, lgValue, RegistryValueKind.DWord)
    
                'check for the key after adding 
                FindAppkey = Convert.ToString(Regkey.GetValue(appName))
            End If
    
            If (FindAppkey = strValue) Then
                MessageBox.Show("Registre de l'application appliquée avec succès")
            Else
                MessageBox.Show("Échec du paramètrage du registre, Ref: " + FindAppkey)
            End If
        Catch ex As Exception
    
    
            MessageBox.Show("Application Settings Failed")
            MessageBox.Show(ex.Message)
    
        Finally
    
            'Close the Registry 
            If (Not Regkey Is Nothing) Then
                Regkey.Close()
            End If
        End Try
    End Sub
    
    0 讨论(0)
  • 2020-11-22 00:06

    Rather than changing the RegKey, I was able to put a line in the header of my HTML:

    <html>
        <head>
            <!-- Use lastest version of Internet Explorer -->
            <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    
            <!-- Insert other header tags here -->
        </head>
        ...
    </html>
    

    See Web Browser Control & Specifying the IE Version.

    0 讨论(0)
  • 2020-11-22 00:07

    just adding the following to your html does the trick no need for registry settigns

    <meta http-equiv="X-UA-Compatible" content="IE=11" >
    
    0 讨论(0)
  • 2020-11-22 00:09

    You can try this link

    try
    {
        var IEVAlue =  9000; // can be: 9999 , 9000, 8888, 8000, 7000
        var targetApplication = Processes.getCurrentProcessName() + ".exe"; 
        var localMachine = Registry.LocalMachine;
        var parentKeyLocation = @"SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl";
        var keyName = "FEATURE_BROWSER_EMULATION";
        "opening up Key: {0} at {1}".info(keyName, parentKeyLocation);
        var subKey = localMachine.getOrCreateSubKey(parentKeyLocation,keyName,true);
        subKey.SetValue(targetApplication, IEVAlue,RegistryValueKind.DWord);
        return "all done, now try it on a new process".info();
    }
    catch(Exception ex)
    {
        ex.log();
        "NOTE: you need to run this under no UAC".info();
    }
    
    0 讨论(0)
  • 2020-11-22 00:11

    It is best to force the highest mode possible. That can be accomplished by adding:

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    

    and it is always good to include the polyfill library in order to support IE:

    <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
    

    before any script.

    0 讨论(0)
  • 2020-11-22 00:15

    Combine the answers of RooiWillie and MohD
    and remember to run your app with administrative right.

    var appName = System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe";
    
    RegistryKey Regkey = null;
    try
    {
        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;
    
        //For 64 bit Machine 
        if (Environment.Is64BitOperatingSystem)
            Regkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
        else  //For 32 bit Machine 
            Regkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
    
        //If the path is not correct or 
        //If user't have priviledges to access registry 
        if (Regkey == null)
        {
            MessageBox.Show("Registry Key for setting IE WebBrowser Rendering Address Not found. Try run the program with administrator's right.");
            return;
        }
    
        string FindAppkey = Convert.ToString(Regkey.GetValue(appName));
    
        //Check if key is already present 
        if (FindAppkey == RegVal.ToString())
        {
            Regkey.Close();
            return;
        }
    
        Regkey.SetValue(appName, RegVal, RegistryValueKind.DWord);
    }
    catch (Exception ex)
    {
        MessageBox.Show("Registry Key for setting IE WebBrowser Rendering failed to setup");
        MessageBox.Show(ex.Message);
    }
    finally
    {
        //Close the Registry 
        if (Regkey != null)
            Regkey.Close();
    }
    
    0 讨论(0)
提交回复
热议问题