保留在本地電腦的一篇記錄,第二條描述是在網(wǎng)上看來的,忘記在哪看的了,也就沒注明出處,望見諒。
1、Winform內(nèi)置瀏覽器控件的底層調(diào)用與系統(tǒng)IE瀏覽器的底層調(diào)用相同。
2、IE8 對渲染引擎做了很大的改動,新增加一個(gè)標(biāo)準(zhǔn)模式 (Standard Mode)。 當(dāng)用戶機(jī)器升級到IE8, WebBrowser控件也會隨之升級到IE8的渲染引擎。為了保證這些使用WebBrowser控件的應(yīng)用軟件能夠工作起來和原來一樣,IE8環(huán)境下的WebBrowser控件在默認(rèn)情況下使用了IE7 的渲染模式(也就是IE8中的Compatible View (兼容視圖)模式),IE9,IE10,IE11默認(rèn)情況下同上所述。通過對系統(tǒng)注冊表進(jìn)行修改,可將該控件修改為標(biāo)準(zhǔn)模式渲染(經(jīng)過本機(jī)IE11測試),修改后客戶端對注冊表的讀取寫入需要相應(yīng)的權(quán)限。
3、關(guān)于構(gòu)建 Chromium內(nèi)核瀏覽器控件的要求;查閱資料后發(fā)現(xiàn)存在 CefSharp 項(xiàng)目可實(shí)現(xiàn)對Chromium內(nèi)核控件的支持,但該項(xiàng)目最低需要.NET4.5.2框架的支持。翻查歷史版本后,該項(xiàng)目大版本號49為支持NET4.0的最后版,版本差距過大,不建議使用。
4、注冊表項(xiàng)添加時(shí)需使用完整的進(jìn)程名,如:chrome.exe。若設(shè)置chrome無效。
5、注冊表位置記錄:
記錄webBrowser控件使用IE渲染版本的路徑:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION;
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION;
記錄當(dāng)前系統(tǒng)IE版本的位置:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer,Version為
當(dāng)前系統(tǒng)自帶IE版本,若存在svcVersion,則此項(xiàng)為升級后的IE版本。
6、添加注冊表時(shí)IE各版本代碼:
switch (IEVersion) { case 7: //7000 (0x1B58) IE7 version = 0x1B58; break; case 8: // 8000 (0x1F40) IE8 version = 0x1F40; break; case 9: //9000 (0×2328) IE9 version = 0x2328; break; case 10: //10000(0×2710) IE10 version = 0x2710; break; case 11: //11000(0×2af8) IE11 version =0x2af8; break; default : version = 0x2328; break; }
/*創(chuàng)建時(shí)間: *創(chuàng)建用途:對固定注冊表項(xiàng)進(jìn)行修改,使得WebBrowser控件使用本機(jī)IE的標(biāo)準(zhǔn)渲染模式對鏈接內(nèi)容進(jìn)行渲染, * 而非默認(rèn)的 兼容模式。 * 本文件獲取IE版本出錯(cuò)時(shí),會將注冊表項(xiàng)默認(rèn)設(shè)置為IE9對應(yīng)的值,原因?yàn)镮E9為win7自帶版本。 */using System;using System.Collections.Generic;using System.Linq;using System.Text;using Microsoft.Win32;using System.Windows.Forms;using System.Diagnostics;namespace XXXXXX{ class SetIEVersionByRegedit { //private bool is64BitSystem = false; const string DEFAULT_IE_VERSION = "9.0"; const string COMMON_PATH_FRONT = @"SOFTWARE"; const string DIFF_BETWEEN_32_AND_64 = @"\Wow6432Node"; const string COMMON_PATH_BEHIND = @"\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION"; //舍棄以下內(nèi)容,注冊表兩項(xiàng)全部寫入 //private int GetBitOperatingSystem () //{ // return Environment.Is64BitOperatingSystem ? 64 : 32; //} //private string GetSettingPath () //{ // int systemBit = GetBitOperatingSystem(); // if (systemBit == 32) // { // return new StringBuilder().Append(COMMON_PATH_FRONT). // } //} public void SetRegistry() { int IEVersion = GetIEVersion(); string itemName = GetItemNameNeedCreat(); uint itemValue = GetItemValueNeedCreat(IEVersion); string path32Key = COMMON_PATH_FRONT + COMMON_PATH_BEHIND; string path64Key = COMMON_PATH_FRONT + DIFF_BETWEEN_32_AND_64 + COMMON_PATH_BEHIND; WriteToRegistry(path32Key, itemName, itemValue); WriteToRegistry(path64Key, itemName, itemValue); } #region 獲取IE版本 private int GetIEVersion () { string version = "9"; try { version = GetIEVersionByWebControl(); } catch { version = GetIEVersionByRegistry(); } return Convert.ToInt32(version); } /// <summary> /// 通過注冊表獲取IE版本,默認(rèn)返回9 /// </summary> /// <returns></returns> private string GetIEVersionByRegistry () { string version = "9.0";//win7自帶 try { RegistryKey ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer"); if(ieKey == null) { return version; } version = ieKey.GetValue("Version").ToString(); //本機(jī)IE升級則存在此項(xiàng) if (ieKey.GetValue("svcVersion") != null) { version = ieKey.GetValue("svcVersion").ToString(); } } catch { } return version.Substring(0, version.IndexOf(".")); } private string GetIEVersionByWebControl () { string version = (new WebBrowser()).Version.Major.ToString(); return version; } #endregion // private uint GetItemValueNeedCreat (int IEVersion) { uint version = 0x2328; switch (IEVersion) { case 7: //7000 (0x1B58) IE7 version = 0x1B58; break; case 8: // 8000 (0x1F40) IE8 version = 0x1F40; break; case 9: //9000 (0×2328) IE9 version = 0x2328; break; case 10: //10000(0×2710) IE10 version = 0x2710; break; case 11: //11000(0×2af8) IE11 version =0x2af8; break; default : version = 0x2328; break; } return version; } private string GetItemNameNeedCreat () { string keyName = "XXXXX.exe"; try { keyName = GetCurrentProessName(); } catch { } return keyName; } private string GetCurrentProessName () { var process = Process.GetCurrentProcess(); string ProcessModuleName = Process.GetCurrentProcess().MainModule.ModuleName; return ProcessModuleName; } private void WriteToRegistry(string keyName,string itemName,object itemValue) { try { if (IsExistSetting( keyName, itemName, itemValue)) { return; } RegistryKey root = Registry.LocalMachine; RegistryKey key = root.OpenSubKey(keyName, true); key.SetValue(itemName, itemValue, RegistryValueKind.DWord); } catch (Exception ex) //設(shè)置出錯(cuò)則使用客戶電腦設(shè)置 { } } private bool IsExistSetting (string keyName, string itemName, object itemValue) { RegistryKey root = Registry.LocalMachine; RegistryKey key = root.OpenSubKey(keyName, true); if(key == null) { return false; } return key.GetValue(itemName,string.Empty).ToString() == itemValue.ToString(); } }}
聯(lián)系客服