C#WebBrowser PanningMode

我正在开发一个实现C#WebBrowser控件的WinForms应用程序。 此应用程序正在部署到Windows 7 SP1 Panasonic触摸屏设备。

很多时候,用户将浏览包含非常大的图像的页面。 为了查看此图像的某些部分,它们需要水平滚动。 虽然通过手指垂直滚动很好,但水平滚动非常不合作。

我看到我们有ScrollViewer.SetPanningMode ,但我们是否有类似WebBrowser的东西?

问题 :我们可以为WebBrowser控件实现平滑的水平触摸滚动吗?

当图像不够高以进行垂直滚动时,无法水平滚动。

也许,我有解决这个平移问题的方法。 它确实需要IE10(桌面),但我记得在评论中读到(它被删除了吗?)这个项目的目标平台是Windows 7,所以希望你有自由在那里部署IE10。 我用我的旧华硕Eee PC T91MT(Windows 7 SP1 w / 平台更新和IE10 )进行了测试,即便在那块硬件上也感觉非常好。

为WinForms或WPF获取一个有效的VS2012项目。

主要观点是:

  • WebBrowser控件启用IE10文档模式 。

  • WebBrowser控件禁用IE Legacy Input Model 。

  • 使用IE10特定的触摸CSS,正如其他读者建议的那样。

代码(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  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:

    

HTML:

          

我无法用IE9测试它,因为我没有IE9的触摸屏机器,虽然我相信它不会工作。 显然,新的Pointer Events Touch API是专为IE10推出的Windows 7(带平台更新 )。

让我们知道它是如何为您服务的。 祝好运!

[EDITED]更新了WinForms项目的链接。