WPF 修改Webbrowser的IE版本(32位)
支持IE11。
XAML页面代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | <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> |
后台代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 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类:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | 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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!