也许,我有一个解决这个平移问题的方法。它确实需要 IE10(桌面),但我记得在评论中读到(它被删除了吗?)这个项目的目标平台是 Windows 7,所以希望你可以自由地在那里部署 IE10。我用我的旧 Asus Eee PC T91MT(Windows 7 SP1 w/ Platform Update和IE10)对其进行了测试,即使在该硬件上也感觉非常好。
为WinForms或WPF获取一个有效的 VS2012 项目。
要点是:
代码(C#):
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Navigation;
namespace WpfWbApp
{
//
// By Noseratio [http://stackoverflow.com/users/1768303/noseratio]
//
// Question: http://stackoverflow.com/questions/17170011/c-sharp-webbrowser-panningmode
//
public partial class MainWindow : Window
{
public MainWindow()
{
SetBrowserCompatibilityMode();
InitializeComponent();
this.Loaded += MainWindow_Loaded;
this.WB.LoadCompleted += WB_LoadCompleted;
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
this.WB.Navigate(new Uri(new Uri(Assembly.GetExecutingAssembly().CodeBase), "content/test.htm").AbsoluteUri);
}
void WB_LoadCompleted(object sender, NavigationEventArgs e)
{
this.WB.Focus();
this.WB.InvokeScript("focus");
}
private void SetBrowserCompatibilityMode()
{
// http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx
// FeatureControl settings are per-process
var fileName = Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);
if (String.Compare(fileName, "devenv.exe", true) == 0) // make sure we're not running inside Visual Studio
return;
using (var key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION",
RegistryKeyPermissionCheck.ReadWriteSubTree))
{
// Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode.
UInt32 mode = 10000; // 10000;
key.SetValue(fileName, mode, RegistryValueKind.DWord);
}
using (var key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BLOCK_LMZ_SCRIPT",
RegistryKeyPermissionCheck.ReadWriteSubTree))
{
// enable <scripts> in local machine zone
UInt32 mode = 0;
key.SetValue(fileName, mode, RegistryValueKind.DWord);
}
using (var key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_NINPUT_LEGACYMODE",
RegistryKeyPermissionCheck.ReadWriteSubTree))
{
// disable Legacy Input Model
UInt32 mode = 0;
key.SetValue(fileName, mode, RegistryValueKind.DWord);
}
}
}
}
XAML:
<Window x:Class="WpfWbApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Touch and pan the picture" Width="1024" Height="800">
<WebBrowser Name="WB"></WebBrowser>
</Window>
HTML:
<!doctype html>
<html>
<head>
<style>
body { -ms-content-zooming:none; -ms-scroll-rails: none; }
</style>
</head>
<body style="overflow: auto">
<img src="panorama.jpg">
</body>
</html>
我无法使用 IE9 对其进行测试,因为我没有带有 IE9 的触摸屏机器,尽管我确信它不会工作。显然,新的Pointer Events Touch API是专门为 IE10为 Windows 7(带有Platform Update)引入的。
让我们知道它是如何为您工作的。祝你好运!
[已编辑]
更新了 WinForms 项目的链接。