MainForm.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using WebKit;
  11. using Microsoft.Win32;
  12. /**
  13. *
  14. * the main application
  15. * */
  16. namespace MainApp
  17. {
  18. public partial class MainForm : Form
  19. {
  20. private System.Windows.Forms.WebBrowser webBrowser1;
  21. public MainForm()
  22. {
  23. InitializeComponent();
  24. }
  25. /// <summary>
  26. /// 窗体加载
  27. /// </summary>
  28. private void Form1_Load(object sender, EventArgs e)
  29. {
  30. //设置IE版本
  31. SetIE(IeVersion.标准ie10);
  32. this.webBrowser1 = new System.Windows.Forms.WebBrowser();
  33. this.webBrowser1.Location = new System.Drawing.Point(0, 0);
  34. this.webBrowser1.MinimumSize = new System.Drawing.Size(0, 0);
  35. this.webBrowser1.Size = new System.Drawing.Size(1300, 756);
  36. this.webBrowser1.TabIndex = 2;
  37. this.webBrowser1.ScriptErrorsSuppressed = true;
  38. //页面URL
  39. this.webBrowser1.Url = new System.Uri("http://tt-web.api.ai160.com/talenkid/build/stage/index/index.html", System.UriKind.Absolute);
  40. this.Controls.Add(this.webBrowser1);
  41. }
  42. /// <summary>
  43. /// 定义IE版本的枚举
  44. /// </summary>
  45. private enum IeVersion
  46. {
  47. 强制ie10,//10001 (0x2711) Internet Explorer 10。网页以IE 10的标准模式展现,页面!DOCTYPE无效
  48. 标准ie10,//10000 (0x02710) Internet Explorer 10。在IE 10标准模式中按照网页上!DOCTYPE指令来显示网页。Internet Explorer 10 默认值。
  49. 强制ie9,//9999 (0x270F) Windows Internet Explorer 9. 强制IE9显示,忽略!DOCTYPE指令
  50. 标准ie9,//9000 (0x2328) Internet Explorer 9. Internet Explorer 9默认值,在IE9标准模式中按照网页上!DOCTYPE指令来显示网页。
  51. 强制ie8,//8888 (0x22B8) Internet Explorer 8,强制IE8标准模式显示,忽略!DOCTYPE指令
  52. 标准ie8,//8000 (0x1F40) Internet Explorer 8默认设置,在IE8标准模式中按照网页上!DOCTYPE指令展示网页
  53. 标准ie7//7000 (0x1B58) 使用WebBrowser Control控件的应用程序所使用的默认值,在IE7标准模式中按照网页上!DOCTYPE指令来展示网页
  54. }
  55. /// <summary>
  56. /// 设置WebBrowser的默认版本
  57. /// </summary>
  58. /// <param name="ver">IE版本</param>
  59. private void SetIE(IeVersion ver)
  60. {
  61. string productName = AppDomain.CurrentDomain.SetupInformation.ApplicationName;//获取程序名称
  62. object version;
  63. switch (ver)
  64. {
  65. case IeVersion.标准ie7:
  66. version = 0x1B58;
  67. break;
  68. case IeVersion.标准ie8:
  69. version = 0x1F40;
  70. break;
  71. case IeVersion.强制ie8:
  72. version = 0x22B8;
  73. break;
  74. case IeVersion.标准ie9:
  75. version = 0x2328;
  76. break;
  77. case IeVersion.强制ie9:
  78. version = 0x270F;
  79. break;
  80. case IeVersion.标准ie10:
  81. version = 0x02710;
  82. break;
  83. case IeVersion.强制ie10:
  84. version = 0x2711;
  85. break;
  86. default:
  87. version = 0x1F40;
  88. break;
  89. }
  90. RegistryKey key = Registry.CurrentUser;
  91. RegistryKey software =
  92. key.CreateSubKey(
  93. @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\" + productName);
  94. if (software != null)
  95. {
  96. software.Close();
  97. software.Dispose();
  98. }
  99. RegistryKey wwui =
  100. key.OpenSubKey(
  101. @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);
  102. //该项必须已存在
  103. if (wwui != null) wwui.SetValue(productName, version, RegistryValueKind.DWord);
  104. }
  105. }
  106. }