WPF WebBrowser - How to increase the content?

An attempt to test the basic browser concepts in a WebBrowser WPF application (C # / XAML, .NET 4.0). So far, the only problem is software scaling. Has anyone had experience with this?

MSDN does not display anything: http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.aspx In addition, I tried various things, such as the RenderTransform options, to no avail. Either this is impossible, or not documented. I hope for the last. Please note that WinForm solution is not acceptable.

Thanks in advance for any help, Beems

+4
source share
3 answers

Perhaps you can execute such javascript.

document.body.style.zoom = 1.5; 

In WPF, we can manipulate a document. I created an extension method for you, so you can install Zoom:

 // www.tonysistemas.com.br public static partial class MyExtensions { public static void SetZoom(this System.Windows.Controls.WebBrowser WebBrowser1, double Zoom) { // For this code to work: add the Microsoft.mshtml .NET reference mshtml.IHTMLDocument2 doc = WebBrowser1.Document as mshtml.IHTMLDocument2; doc.parentWindow.execScript("document.body.style.zoom=" + Zoom.ToString().Replace(",", ".") + ";"); } } 

Using:

 WebBrowser1.SetZoom(0.5); 
+6
source

I used bits and pieces from this answer fooobar.com/questions/890726 / ... to help with the scaling issue. The key here is the ExecWB method. Scaling on the Windows desktop is not 1-1 for zooming in on a web browser. You will have to play with him. The pseudocode for the equation looks like this:

 zoomLevel = (winDesktopZoom - 100) + _winDesktopZoom + 10 

Note that you will need a link to SHDocVw.dll, which can be found on computers C: \ Windows \ SysWOW64 for x64 and in C: \ Windows \ System32 for x86 machines.

Itโ€™s not very, but itโ€™s the only thing Iโ€™ve found that it doesnโ€™t reach http://awesomium.com , which actually matches the IE default settings (which are used by default to scale Windows Desktop) to control the web browser. Also note that Windows Desktop Zoom exists only for Vista, Win 7 and probably 2k8, as well as in Control Panel โ†’ Display, but I have not tested Vista or 2k8. This does not exist for XP (any service pack).

To get Windows Desktop Zoom (for some reason this works on XP), I did:

 var presentSource = PresentationSource.FromVisual(this); if (presentSource != null && presentSource.CompositionTarget != null && presentSource.CompositionTarget.TransformToDevice != null) { _zoomPercentage = Convert.ToInt32(100 * presentSource.CompositionTarget.TransformToDevice.M11); } 

This logic is placed in the OnSourceInitialized override for this XAML window.

+1
source

Source: https://habr.com/ru/post/890728/


All Articles