最近做一个WPF触屏的项目,引用到WebBrowser控件,由于是触屏的所以控件里的网页可以缩放,客户提出要求,屏蔽这缩放功能。

于是网上找了很多资料,也换过控件,WebView2 控件使用Microsoft Edge (Chromium)作为呈现引擎。
后来找到一个完美的解决方案,我在这里直接共享出来。

一、设置浏览器仿真

  Windows Internet Explorer 8及以后版本。feature_browser_simulation特性定义了Internet Explorer的默认模拟模式,并支持以下值。

11001 (0x2AF9 Internet Explorer 11. Webpages are displayed in IE11 edge mode, regardless of the declared !DOCTYPE directive. Failing to declare a !DOCTYPE directive causes the page to load in Quirks.
11000 (0x2AF8) IE11. Webpages containing standards-based !DOCTYPE directives are displayed in IE11 edge mode. Default value for IE11.
10001 (0x2711) Internet Explorer 10. Webpages are displayed in IE10 Standards mode, regardless of the !DOCTYPE directive.
10000 (0x02710) Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode. Default value for Internet Explorer 10.
9999 (0x270F) Windows Internet Explorer 9. Webpages are displayed in IE9 Standards mode, regardless of the declared !DOCTYPE directive. Failing to declare a !DOCTYPE directive causes the page to load in Quirks.
9000 (0x2328) Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.

Important In Internet Explorer 10, Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode.
 
8888 (0x22B8) Webpages are displayed in IE8 Standards mode, regardless of the declared !DOCTYPE directive. Failing to declare a !DOCTYPE directive causes the page to load in Quirks.
8000 (0x1F40) Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. Default value for Internet Explorer 8

Important In Internet Explorer 10, Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode.
 
7000 (0x1B58) Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. Default value for applications hosting the WebBrowser Control.

  1.找到注册表项:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION

  2.添加DWORD(32位)值,重命名为你的程序名,例如QQMusic.exe
  3.根据上面对应的数值设置十进制数值;

二、禁用阻塞本地Script脚本

  Internet Explorer 7及以后版本。在启用阻塞本地Script脚本特性时,允许存储在本地机器区域的脚本仅在从本地机器区域加载的网页上运行。
  该属性默认时启用的(DWORD) 00000001,我们需将他设为禁用(DWORD) 00000000.

  1.找到注册表项:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BLOCK_LMZ_SCRIPT 

  2.添加DWORD(32位)值,并重命名
  3.修改十进制数值为0

三、禁用传统输入模式
  由于微软在Windows 8以上引入了新的输入模式,为了使遗留的应用程序提供最广泛的兼容性,WebBrowser控件在Windows 8以上的系统中会模拟Windows 7鼠标、触摸和笔的输入模式。

  传统输入模式启用时:
  1.Trident渲染引擎(mshtml.dll)不处理Windows指针消息。
  2.文档对象模型(DOM)指针和手势事件不会触发。
  3.鼠标和触摸信息按Windows 7输入模式发送。
  4.触摸选择遵循Windows 7模式(“拖动至选择”),而不是Windows 8模式(“点击至选择”)。
  5.硬件加速平移和缩放被禁用。
  6.Zoom和Pan样式属性将会被忽略

  第5条和第6条就是导致我不管怎么去改html样式,都无法屏蔽缩放的原因。因为传统输入模式默认是没有开启的,我们只需将他启用,就可以禁用WebBrowser的触屏功能了。

  1.找到注册表项:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControlFEATURE_NINPUT_LEGACYMOD

  2.添加DWORD(32位)值,并重命名
  3.修改十进制数值为0

我们只需在WebBrowser初始化之前调用以下方法:

private void SetBrowSerCompatibilityModel()
{
//获取程序名称
var fileName = Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);
if (string.Compare(fileName, "devenv.exe", true) == )//确定不是在vs中运行
return; //设置浏览器仿真
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION",
RegistryKeyPermissionCheck.ReadWriteSubTree))
{
key.SetValue(fileName, (uint), RegistryValueKind.DWord);
} //禁用阻塞本地Script脚本
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BLOCK_LMZ_SCRIPT",
RegistryKeyPermissionCheck.ReadWriteSubTree))
{
key.SetValue(fileName, (uint), RegistryValueKind.DWord);
}
//禁用传统输入模式
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_NINPUT_LEGACYMOD",
RegistryKeyPermissionCheck.ReadWriteSubTree))
{
key.SetValue(fileName, (uint), RegistryValueKind.DWord);
}
}

WebBrowser禁用触摸缩放的更多相关文章

  1. CentOS禁用触摸板

    安装xorg-x11-apps包 yum install xorg-x11-apps 查看设备信息 cd /dev/input/ ls //找到触摸板信息 xinput list //找到触摸板的id ...

  2. Ubuntu 12.04 禁用触摸板

    昨天把系统换为Backbox了,版本为Ubuntu12.04,装完后发现其触摸板不能禁用,之前在其他版本都是直接快捷键就可关闭或者启用触摸板,解决方法如下: sudo add-apt-reposito ...

  3. T450设置插入USB鼠标时自动禁用触摸板

    刚入手T450,打字时经常碰到触摸板,很是恼火,于是求助万能的度娘,找了卡饭基佬的教程,实测可行,大家可以试试.<win7下如何设置插入USB鼠标时自动禁用触摸板>,地址:www.kafa ...

  4. ThinkPad 禁用 触摸板

    执行 xinput wowk@wowk:~$ xinput ⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTES ...

  5. win10连接外接鼠标怎么禁用触摸板

    Win10笔记本如何禁用触摸板呢?Win10笔记本如何设置“插入鼠标自动禁止触摸板功能”呢?虽然笔记本触摸板在一定程度上可以方便我们的 操作,但是在以鼠标和键盘做为重要的输入设备的情况下,笔记本触摸板 ...

  6. Ubuntu系统使用命令禁用触摸板等输入设备

    [日期:2012-02-22]   本人用的Ubuntu 10.04系统,笔记本上有鼠标和触摸板.默认下,触摸板是开启的, 有时候打字的时候会不时碰到触摸板,添了不少麻烦,所以得禁用触摸板,限于目前所 ...

  7. ubuntu 12.10 禁用触摸板

    1. 打开终端,输入 sudo rmmod psmouse 禁用触摸板,输入 sudo modprobe psmouse 恢复触摸板 2.syndaemon -i 10 -d >/dev/nul ...

  8. WebBrowser 禁用右键

    禁用错误脚本提示 将 WebBrowser控件的 ScriptErrorsSuppressed 设为 true 禁用右键菜单 将 WebBrowser 的 IsWebBrowserContextMen ...

  9. SL410K 在Ubuntu禁用触摸板

    由于之前把系统自带的恢复去了,然后TouchPad一直不能禁用,而后我的410k就只装上ubuntu,想不到在ubuntu上,禁用/启用 触摸板这么方便. http://askubuntu.com/q ...

随机推荐

  1. STM32串口DMA接收数据错位——暴力解决方法

    背景:两片STM32通过串口通信,为了减小CPU负担,采用DMA进行通信,发送端为STM32F103C8T6,接收端为STM32F407VET6.在调试的过程中发现,一直出现数据错位的问题,接收端尝试 ...

  2. Chisel3 - model - Hardware Model

    https://mp.weixin.qq.com/s/x6j7LZg7i7i_KcNEA8YCQw   Chisel作为领域专用语言(DSL),用于构建硬件模型.待硬件模型建立后,再基于模型进行仿真. ...

  3. jchdl - RTL实例 - Adder4Carry

    https://mp.weixin.qq.com/s/j4zLmjKgau2vRXVNfm0SIA   带进位的加法.   参考链接 https://github.com/wjcdx/jchdl/bl ...

  4. SpringMVC(四)SpringMVC实现文件上传、异常拦截去、整合SSM

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) 一.文件上传 文件上传在SpringMVC中如何实现: 准备一个文件上传的表单 导入文件上传需要的jar ...

  5. Java实现 LeetCode 822 翻转卡片游戏(暴力)

    822. 翻转卡片游戏 在桌子上有 N 张卡片,每张卡片的正面和背面都写着一个正数(正面与背面上的数有可能不一样). 我们可以先翻转任意张卡片,然后选择其中一张卡片. 如果选中的那张卡片背面的数字 X ...

  6. Java实现 LeetCode 768 最多能完成排序的块 II(左右便利)

    768. 最多能完成排序的块 II 这个问题和"最多能完成排序的块"相似,但给定数组中的元素可以重复,输入数组最大长度为2000,其中的元素最大为10**8. arr是一个可能包含 ...

  7. Java实现 蓝桥杯VIP 算法训练 简单加法

    时间限制:1.0s 内存限制:512.0MB 问题描述 首先给出简单加法算式的定义: 如果有一个算式(i)+(i+1)+(i+2),(i>=0),在计算的过程中,没有任何一个数位出现了进位,则称 ...

  8. Java实现 LeetCode 313 超级丑数

    313. 超级丑数 编写一段程序来查找第 n 个超级丑数. 超级丑数是指其所有质因数都是长度为 k 的质数列表 primes 中的正整数. 示例: 输入: n = 12, primes = [2,7, ...

  9. java实现正六面体染色

    ** 正六面体染色** 正六面体用4种颜色染色. 共有多少种不同的染色样式? 要考虑六面体可以任意旋转.翻转. 参考答案: 240 Burnside引理,正方体涂色问题 (n^6 + 3*n^4 + ...

  10. java实现第四届蓝桥杯买不到的数目

    买不到的数目 题目描述 小明开了一家糖果店.他别出心裁:把水果糖包成4颗一包和7颗一包的两种.糖果不能拆包卖. 小朋友来买糖的时候,他就用这两种包装来组合.当然有些糖果数目是无法组合出来的,比如要买 ...