支持IE11。
XAML页面代码
<Window.Resources> <ObjectDataProvider x:Key="ieList" MethodName="GetValues" ObjectType="{x:Type sys:Enum}"> <ObjectDataProvider.MethodParameters> <x:Type TypeName="local:IEVersion"/> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> </Window.Resources> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <ListBox BorderThickness="0,0,1,0" MinWidth="150" ItemsSource="{Binding Source={StaticResource ieList}}" x:Name="IETypeList" Grid.Column="0"/> <Grid Grid.Column="1"> <Grid.Resources> <Style TargetType="Grid"> <Setter Property="Margin" Value="0,0,0,10"/> </Style> </Grid.Resources> <Grid.RowDefinitions> <RowDefinition Height="auto"/> <RowDefinition Height="auto"/> <RowDefinition Height="auto"/> <RowDefinition Height="auto"/> </Grid.RowDefinitions> <Grid Grid.Row="0" > <Grid.ColumnDefinitions> <ColumnDefinition Width="auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <TextBlock Text="IE版本"/> <TextBlock Margin="10,0,0,0" Grid.Column="1" Foreground="Red" Text="{Binding ElementName=IETypeList,Path=SelectedItem}" /> </Grid> <Grid Grid.Row="1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <TextBlock Text="程序名称(不用.exe)"/> <TextBox Margin="10,0,0,0" Grid.Column="1" x:Name="ProgramNAME"/> </Grid> <Grid Grid.Row="2"> <Button Content="写入" x:Name="WriteBtn" Click="WriteBtn_Click"/> </Grid> </Grid> </Grid>
后台代码:
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void WriteBtn_Click(object sender, RoutedEventArgs e) { if (IETypeList.SelectedIndex < 0) return; if (ProgramNAME.Text.Length < 0 || string.IsNullOrWhiteSpace(ProgramNAME.Text)) return; var select = (IEVersion)IETypeList.SelectedItem; var name = ProgramNAME.Text+=".exe"; IE.SetIE(select, name); ProgramNAME.Text.Replace(".exe", string.Empty); } }
IE类:
public enum IEVersion { 强制ie11,//11001 标准ie11,//11000 强制ie10,//10001 (0x2711) Internet Explorer 10。网页以IE 10的标准模式展现,页面!DOCTYPE无效 标准ie10,//10000 (0x02710) Internet Explorer 10。在IE 10标准模式中按照网页上!DOCTYPE指令来显示网页。Internet Explorer 10 默认值。 强制ie9,//9999 (0x270F) Windows Internet Explorer 9. 强制IE9显示,忽略!DOCTYPE指令 标准ie9,//9000 (0x2328) Internet Explorer 9. Internet Explorer 9默认值,在IE9标准模式中按照网页上!DOCTYPE指令来显示网页。 强制ie8,//8888 (0x22B8) Internet Explorer 8,强制IE8标准模式显示,忽略!DOCTYPE指令 标准ie8,//8000 (0x1F40) Internet Explorer 8默认设置,在IE8标准模式中按照网页上!DOCTYPE指令展示网页 标准ie7//7000 (0x1B58) 使用WebBrowser Control控件的应用程序所使用的默认值,在IE7标准模式中按照网页上!DOCTYPE指令来展示网页 } public class IE { public static void SetIE(IEVersion ver, string Name) { string productName = Name;//获取程序名称 object version; switch (ver) { case IEVersion.标准ie7: version = 0x1B58; break; case IEVersion.标准ie8: version = 0x1F40; break; case IEVersion.强制ie8: version = 0x22B8; break; case IEVersion.标准ie9: version = 0x2328; break; case IEVersion.强制ie9: version = 0x270F; break; case IEVersion.标准ie10: version = 0x02710; break; case IEVersion.强制ie10: version = 0x2711; break; case IEVersion.标准ie11: version = 0x2AF8; break; case IEVersion.强制ie11: version = 0x2EDF; break; default: version = 0x1F40; break; } RegistryKey key = Registry.CurrentUser; RegistryKey software = key.CreateSubKey( @"Software/Microsoft/Internet Explorer/Main/FeatureControl/FEATURE_BROWSER_EMULATION/" + productName); if (software != null) { software.Close(); software.Dispose(); } RegistryKey wwui = key.OpenSubKey( @"Software/Microsoft/Internet Explorer/Main/FeatureControl/FEATURE_BROWSER_EMULATION", true); //该项必须已存在 if (wwui != null) { wwui.SetValue(productName, version, RegistryValueKind.DWord); MessageBox.Show("写入完毕"); } else MessageBox.Show("写入失败"); } }
程序截图
源代码和程序下载
文章作者:https://www.cnblogs.com/T-ARF/category/1338276.html
原创文章,作者:3628473679,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/275121.html