參考:
- http://www.dotblogs.com.tw/larrynung/archive/2012/10/15/77505.aspx
- http://msdn.microsoft.com/en-us/library/ee330730%28v=vs.85%29.aspx#browser_emulation
var appName = Process.GetCurrentProcess().MainModule.ModuleName;
Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION", appName, 9999, RegistryValueKind.DWord);
InitializeComponent();
專案下載:NewBrowser.zip
在 C# 中使用 WebBrowser 控制項時,預設使用的是 IE4 (也太老了吧!),並不會自動隨著使用者的更新而改用新的控件,此時您必須更新系統註冊碼,讓 Windows 系統知道你的程式想使用新版的 IE,以下是筆者的參考資料:
It appears you need to fiddle with the registry as per this article: - http://blogs.msdn.com/ie/archive/2009/03/10/more-ie8-extensibility-improvements.aspx
To run a WebBrowser control in IE8 Standards Mode, use the following new value into the registry:
[(HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE)\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION] "MyApplication.exe" = dword 8000 (Hex: 0x1F40)
To run in IE7 Standards Mode, use the following registry value:
[(HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE)\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION] "MyApplication.exe" = dword 7000 (Hex: 0x1B58)
For IE8 RTM, we’ve added a new “forced” IE8 Standards Mode value. When an application opts into this mode, the Web Browser control will use the IE8 User-Agent string and Browser Emulation mode strictly. It will also ignore fallback features such as the built-in Compatibility View list and the user-generated Compatibility View list when loading pages. To run in “forced” IE8 Standards Mode, use the following registry value:
[(HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE)\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION] "MyApplication.exe" = dword 8888 (Hex: 0x22B8)
In all of these examples, “MyApplication.exe” refers to the name of your application.
為了讓您的程式在發布後,都可以強制所有電腦使用新版的 IE,您可以將下列程式放在 Form 一開始啟動的時候,或者是放在 Application 的 Main 程式中,如下所示:
...
public Form1() A
{
InitializeComponent();
Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\
FeatureControl\FEATURE_BROWSER_EMULATION",
"Browser.exe", "dword 8000");
Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\
FeatureControl\FEATURE_BROWSER_EMULATION",
"Browser.vshost.exe", "dword 8000");
}
...
參考文獻
- C# Web Browser component is IE7 not IE8? How to change this?
- 如何為 WebBrowser 控制項主機處理指令碼錯誤
陳鍾誠 (2011年12月19日),(網頁標題) C# 視窗程式:如何使用新版的瀏覽器控件?,(網站標題) 免費電子書:C# 程式設計,2011年12月19日,取自 http://cs0.wikidot.com/newbrowser ,網頁修改第 13 版。