基本信息
源码名称:切换IE版本工具 实例源码
源码大小:0.02M
文件格式:.zip
开发语言:C#
更新时间:2015-07-11
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
using Cyotek.ApplicationServices.Windows.Forms;
namespace IeBrowserEmulation
{
// Configuring the emulation mode of an Internet Explorer WebBrowser control
// http://cyotek.com/blog/configuring-the-emulation-mode-of-an-internet-explorer-webbrowser-control
public partial class MainForm : Form
{
#region Instance Fields
private WebBrowser _webBrowser;
#endregion
#region Public Constructors
public MainForm()
{
InitializeComponent();
}
#endregion
#region Overridden Methods
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing)
{
this.RemoveWebBrowser();
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
/// <summary>
/// Raises the <see cref="E:System.Windows.Forms.Form.Load"/> event.
/// </summary>
/// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data. </param>
protected override void OnLoad(EventArgs e)
{
int internetExplorerMajorVersion;
base.OnLoad(e);
this.Font = SystemFonts.MessageBoxFont;
ieVersionLabel.Font = new Font(this.Font.FontFamily, 20F, FontStyle.Bold);
// show the ie version which will help explain why any controls are disabled
internetExplorerMajorVersion = InternetExplorerBrowserEmulation.GetInternetExplorerMajorVersion();
ieVersionLabel.Text = internetExplorerMajorVersion.ToString(CultureInfo.InvariantCulture);
// use reflection to build the radio controls, so I don't need to do anything when adding new values to the enum
this.BuildEmulationRadioButtonList();
// update the preview
this.UpdatePreview(InternetExplorerBrowserEmulation.GetBrowserEmulationVersion());
}
#endregion
#region Private Members
private void BuildEmulationRadioButtonList()
{
int x;
int y;
BrowserEmulationVersion currentEmulationVersion;
currentEmulationVersion = InternetExplorerBrowserEmulation.GetBrowserEmulationVersion();
x = emulationGroupBox.DisplayRectangle.X;
y = emulationGroupBox.DisplayRectangle.Y;
foreach (BrowserEmulationVersion version in Enum.GetValues(typeof(BrowserEmulationVersion)))
{
RadioButton control;
control = new RadioButton
{
Text = version.ToString(),
Tag = version,
AutoSize = true,
Left = x,
Top = y,
Checked = (version == currentEmulationVersion)
};
control.Click = this.EmulationVersionRadioButtonClickHandler;
emulationGroupBox.Controls.Add(control);
y = (control.Height control.Margin.Bottom);
}
// move the restart warning below the list
restartWarningLabel.Top = y restartWarningLabel.Margin.Top;
}
private void RemoveWebBrowser()
{
if (_webBrowser != null)
{
if (_webBrowser.Parent != null)
{
_webBrowser.Parent.Controls.Remove(_webBrowser);
}
_webBrowser.Dispose();
_webBrowser = null;
}
}
private void UpdatePreview(BrowserEmulationVersion version)
{
this.RemoveWebBrowser();
_webBrowser = new WebBrowser
{
Dock = DockStyle.Fill
};
previewGroupBox.Controls.Add(_webBrowser);
_webBrowser.Navigate(new Uri("http://cyotek.com/"));
}
#endregion
#region Event Handlers
private void EmulationVersionRadioButtonClickHandler(object sender, EventArgs e)
{
RadioButton button;
BrowserEmulationVersion version;
button = (RadioButton)sender;
version = (BrowserEmulationVersion)button.Tag;
if (InternetExplorerBrowserEmulation.GetBrowserEmulationVersion() != version)
{
// apply the new emulation version
if (!InternetExplorerBrowserEmulation.SetBrowserEmulationVersion(version))
{
MessageBox.Show("Failed to update browser emulation version.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
// now destroy and recreate the WebBrowser control
Application.Restart();
Environment.Exit(-1);
}
}
}
private void closeButton_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
}
}