我想在Winforms Web浏览器控件中使用拼写检查工作。浏览器控件中的拼写检查不能在IE11仿真下工作
这是我目前的C#代码:
try
{
String appname = Process.GetCurrentProcess().ProcessName + ".exe";
RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", RegistryKeyPermissionCheck.ReadWriteSubTree);
object ieVal = key.GetValue(appname, null);
MessageBox.Show(ieVal.ToString());
if (ieVal == null || (int)ieVal != 11001)
{
key.SetValue(appname, 11001, RegistryValueKind.DWord);
}
key.Close();
}
catch
{
MessageBox.Show("Registry stuff didn't work");
}
MessageBox.Show(webBrowser1.Version.ToString());
webBrowser1.DocumentText = "<html><head><body><div spellcheck=\"true\" style=\"width:100%; height:100%;\" contenteditable=\"true\"></div>"
+"<script>alert(navigator.userAgent);</script>"
+"</body></html>";
所以首先我设置适当的注册表项,使浏览器模拟IE11
然后我添加一个div标签设置为true拼写检查属性。
版本的MessageBox.Show(webBrowser1.Version.ToString())
显示的是:
11.0.9600.18525
的navigator.userAgent
表明,JavaScript显示为:
Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
所以它看起来像Web浏览器控件使用IE11。但是当我输入拼写检查不起作用。
注意:当我运行的HTML代码与真正的IE浏览器一切正常。
此外,在实际的浏览器显示的navigator.userAgent
是:
Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; rv:11.0) like Gecko
注2:当我运行我的Windows 10计算机进行拼写检查工程应用。但我需要使它在Windows 7机器上运行。
spellchek?滑稽! – TaW