Page 1 of 1

Zoom on initialise

PostPosted: Mon Apr 04, 2016 8:43 am
by samgplay
HI all,
Does anyone have or know the solution to the following issue,

I set the zoom level of the web browser as its initialised but the zoom level doesn't seem to do anything. is there another way to set the zoom level as the page is loaded as so far the only way i can get this to work is by having a timer wait for several seconds then setting the zoom level.

webBrowser.IsBrowserInitializedChanged += WebBrowserOnIsBrowserInitializedChanged;



private void WebBrowserOnIsBrowserInitializedChanged(object sender, IsBrowserInitializedChangedEventArgs isBrowserInitializedChangedEventArgs)
{
ChromiumWebBrowser webBrowser = (ChromiumWebBrowser)sender;

if (webBrowser.IsBrowserInitialized)
{
webBrowser.SetZoomLevel(-2.0);
}
}

this code runs but the set zoom level method does nothing

Re: Zoom on initialise

PostPosted: Tue Apr 05, 2016 4:22 am
by samgplay
I have found the solution to this. instead of using the on initialized event I instead used the web browsers loading state changed event and checked inside here if the page has finished loading.

webBrowser.LoadingStateChanged += WebBrowserOnLoadingStateChanged;

private void WebBrowserOnLoadingStateChanged(object sender, LoadingStateChangedEventArgs loadingStateChangedEventArgs)
{
ChromiumWebBrowser web = (ChromiumWebBrowser)sender;
if (!web.IsLoading)
{
web.SetZoomLevel(Zoom);
}
}

This seems to work for what i needed