C# WebBrowser的PanningMode

4
我正在开发一个WinForms应用程序,该应用程序实现了C# WebBrowser控件。该应用程序将部署到Windows 7 SP1 Panasonic触摸屏设备上。
很多时候,用户会浏览包含非常大的图像的页面。为了看到这个图像的各个部分,他们需要水平滚动。虽然手指的垂直滚动是好的,但是水平滚动非常不协调。
我看到我们有ScrollViewer.SetPanningMode,但是WebBrowser有类似的东西吗?
问题:我们能否为WebBrowser控件实现平稳的水平触摸滚动?
当图像不足以进行垂直滚动时,水平滚动变得不可能。

当图像在水平方向上延伸超出浏览器窗口,但不足以在垂直方向上延伸页面时,这将成为更大的问题。在这种情况下,在Windows Mobile设备上无法向右滚动。 - teynon
也许这个链接和示例会有所帮助?http://msdn.microsoft.com/en-us/library/ie/hh920761(v=vs.85).aspx - sara
@zewa666,我猜测这是WPF WebBrowser(?),因为提到了ScrollViewer.SetPanningMode - noseratio - open to work
是的,但它们实现了基于使用的.NET框架的不同版本的IE。因此,我建议首先在特定的IE中测试页面,以查看是否存在HTML/CSS特定问题。 - zewa666
很不幸,这是一个Win Forms应用程序。 - teynon
显示剩余4条评论
1个回答

4
也许我有解决这个滚动问题的方法。它需要IE10(桌面版),但我记得在评论中读到过(被删除了吗?)这个项目的目标平台是Windows 7,所以希望你有自由在那里部署IE10。我在我的旧Asus Eee PC T91MT上进行了测试(Windows 7 SP1 w/平台更新IE10),即使在那种硬件上,感觉还不错。

获取一个可用的VS2012项目,用于WinFormsWPF

主要要点如下:

代码(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: https://dev59.com/73PYa4cB1Zd3GeqPi3Jr
    //

    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机器,所以无法测试它,尽管我确定它不会工作。显然,新的Pointer Events Touch API是为Windows 7(通过Platform Update专门为IE10引入的。
告诉我们它对你有什么作用。祝你好运!

[编辑] 更新了一个指向WinForms项目的链接。


这是一个Windows Forms应用程序,但我会尝试让它工作。 - teynon
我已经运行了你的项目并制作了自己的版本,但是用手指水平滑动仍然无法工作,除非我先向下滚动(垂直方向)。我在Win7 SP1设备上安装了IE10。我正在使用一个随机网站进行测试:http://pic.templetons.com/cgi-bin/imget?f=brad/pano/midpano/center-wide.jpg&fw=15547 - teynon
1
我有VS2010,所以无法直接打开你的项目。但是使用你的代码和文件创建一个VS2010项目会得到相同的结果。我不确定手持设备是否有平台更新。但如果没有的话,我就无法安装它。我使用的设备是来自一家大公司的镜像,即使说服他们升级到IE10也很可能不会发生。如果唯一的实现方式是通过更新,那么我将无法测试,因为我无法控制用户要浏览的网站,也无法控制设备上的其他软件。 - teynon
在图像上水平拖动会像我试图将其拖放到某个地方一样拾取图像。不过还是谢谢你的尝试。 - teynon
没问题。我不知道我的Win7平板电脑和你的硬件有什么不同,但这种事情经常发生。我还在Win8触摸屏笔记本上尝试过,那里运行非常流畅。无论如何,这是我能做到的最好的了。 - noseratio - open to work
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接