How to disable WebBrowser control zoom and move left and right

Source: Internet
Author: User

I think there are two ways to do this. 1, WebBrowser is based on IE 9, so WebBrowser is also supporting the latest HTML5 standards. However, there are many controls in HTML that work with handheld behaviors like pan and zoom in browser, and you can set viewport metadata elements in HTML. For example, add the following HTML code to your HTML file header. <meta name= "viewport" content= "User-scalable=no"/>2, the Webbroswer control is composed of a tree structure such as: \-webbrowser
  \- Border
    \-border
      \-panzoomcontainer
         \-grid
          \-border (*)
           & Nbsp;\-contentpresenter
              \-tilehost
where Tilehost is the original IE9 component, Tilehost does not handle all manipulation related events, but is handled by Panzoomcontainer, converting these events to handheld and then transferring the results to Tilehost. In other words we can interrupt the related Manipulationg event transmission to Panzoomcontainer. When these events are not bubble up to Panzoomcontainer, when these events are set to already processed. The key steps of this approach are 2 steps: 1, you need to find the border control from the Webbroswer component tree. 2, handles manipulation related events, and sets the event has been processed e.handled = true;
For example:

Using Linqtovisualtree;

public class Webbrowserhelper

{

Public WebBrowser _browser;

<summary>

Gets or sets whether to suppress the scrolling of

The WebBrowser control;

</summary>

public bool scrolldisabled {get; set;}

Public Webbrowserhelper (WebBrowser browser)

{

_browser = browser;

Browser. Loaded + = new Routedeventhandler (browser_loaded);

}

private void Browser_loaded (object sender, RoutedEventArgs e)

{

var border = _browser. Descendants<border> (). Last () as Border;

Border. Manipulationdelta + = Border_manipulationdelta;

Border. manipulationcompleted + = border_manipulationcompleted;

}

private void Border_manipulationcompleted (object sender,

ManipulationCompletedEventArgs e)

{

Suppress zoom

if (e.finalvelocities.expansionvelocity.x! = 0.0 | |

E.finalvelocities.expansionvelocity.y! = 0.0)

E.handled = true;

}

private void Border_manipulationdelta (object sender,

Manipulationdeltaeventargs e)

{

Suppress zoom

if (e.deltamanipulation.scale.x! = 0.0 | |

E.deltamanipulation.scale.y! = 0.0)

E.handled = true;

Optionally suppress scrolling

if (scrolldisabled)

{

if (e.deltamanipulation.translation.x! = 0.0 | |

E.deltamanipulation.translation.y! = 0.0)

E.handled = true;

}

}

}

Detailed Description: http://wp.662p.com/thread-7952-1-1.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.