Zoom

This guide describes how to work with DotNetBrowser Zoom API.

DotNetBrowser allows to zoom content of a web page or all ones, receive notifications of web page zoom level change, override the default zoom level, and other features.

To work with the global zoom that will be applied to all web pages, use the IEngine.ZoomLevels property.

To control zoom of a web page loaded in the IBrowser instance, use the IBrowser.Zoom property.

Default Zoom Level

The default zoom level for all web pages is 100%. You can change it using the IZoomLevels.DefaultLevel property.

The code sample below sets the default zoom level for all web pages to 150%:

engine.ZoomLevels.DefaultLevel = Level.P150;

Controlling zoom

You can zoom content of a web page loaded in IBrowser programmatically using the IZoom instance or using touch gestures in the environments with a touch screen.

Zoom level is configured for each host separately. If you set a zoom level for the http://www.a.com web page, it does not affect the http://www.b.com web page.

To change the zoom level, you need to wait until the web page is loaded completely.

Zooming in

To zoom in a currently loaded web page, use the following method:

browser.Zoom.In();

Zooming out

To zoom out a currently loaded web page, use the following method:

browser.Zoom.Out();

Setting zoom level

The following code sample sets zoom level of the loaded web page to 200%:

browser.Zoom.Level = Level.P200;

Resetting the zoom

To reset zoom level to the default value, use the code sample below:

browser.Zoom.Reset();

Disabling the zoom

You can disable zoom for all web pages loaded in the IBrowser using the IZoom.Enabled property. It enables or disables the zoom functionality and resets the zoom level to the default value. After that any attempts to change the zoom level programmatically using DotNetBrowser Zoom API and
touch gestures on a touch screen device are ignored.

For example:

browser.Zoom.Enabled = false;

Zoom events

To get notifications of zoom level change for particular web page, use the ZoomChanged event. See the code sample below:

engine.ZoomLevels.LevelChanged += (s, e) =>
{
    string hostUrl = e.Host;
    Level zoomLevel = e.Level;
};
Go Top