本文介绍了C#的WebBrowser PanningMode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作就是实现一个C#WebBrowser控件WinForms应用程序。本申请是在部署到Windows 7 SP1松下触摸屏设备

I'm working on a WinForms application that is implementing a C# WebBrowser control. This application is deploying to a Windows 7 SP1 Panasonic touch screen device.

许多时候,用户将被浏览含有非常大的图像的页面。为了看到这个形象的地方,他们将需要横向滚动。同时通过手指垂直滚动是好的,水平滚动非常不合作。

Many times, the user will be browsing a page containing a very large image. In order to see parts of this image, they will need to scroll horizontally. While the vertical scrolling via finger is fine, horizontal scrolling is very uncooperative.

我看到我们有的,但确实我们已经为web浏览器类似的东西?

I see we have ScrollViewer.SetPanningMode, but do we have something similar for the WebBrowser?

:我们能否实现平稳水平的触摸滚动的WebBrowser控件

Question: Can we achieve smooth horizontal touch scrolling for a WebBrowser control?

当图像不是垂直滚动足够高,就不可能水平滚动。

When the image isn't high enough for vertical scrolling, it becomes impossible to scroll horizontally.

推荐答案

也许,我有一个解决方案这个平移问题。它要求IE10(桌面),但我记得读的评论(它是否删除了?),为了这个项目中的目标平台是Windows 7,所以希望你有自由有部署IE10。我用我的旧华硕Eee PC T91MT(Windows 7的SP1瓦特/ 和 IE10 ),它甚至在那块感觉不错硬件。

Perhaps, I have a solution to this panning problem. It does require IE10 (Desktop), but I remember reading in the comments (was it deleted?) that the target platform for this project is Windows 7, so hopefully you have freedom to deploy IE10 there. I tested it with my old Asus Eee PC T91MT (Windows 7 SP1 w/ Platform Update and IE10) and it felt pretty good even on that piece of hardware.

抢 。或

主要的要点是:


  • 启用的控制。

  • Enable IE10 document mode for WebBrowser control.

IE为 web浏览器旧式输入型号控制

Disable IE Legacy Input Model for WebBrowser control.

使用的。

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

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,虽然我敢肯定,这是行不通的。显然,新的被介绍为Windows 7(与)的。

I could not test it with IE9 as I don't have a touch-screen machine with IE9, although I'm sure it would not work. Apparently, the new Pointer Events Touch API was introduced for Windows 7 (with Platform Update) specifically for IE10.

让我们知道如何为你工作。祝你好运!

Let us know how it works for you. Good luck!


有链接的。

这篇关于C#的WebBrowser PanningMode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 07:59