WPF Web browser control inheriting Internet explorer zoom level - c#

I have a web browser control hosted on a WPF window so I can display html/css pages. I am having issues with my web browser control using Internet Explorer's zoom factor. The web browser control takes internet explorers zoom level to distort and mess up the way my HTML looks.
For example, if I set Internet Explorer to zoom at 150%, and the web browser will start zoomed in 150%.
I've tried using the zoom CSS property and the HTML document.style.zoom but the browser ignores my changes and takes IE's zoom. Is there a way to ignore Internet Explorer options through either my C# or overwrite them in my HTML/CSS?

Well, after searching through the internet I didn't find too many viable solutions.
I did think of a temporary workaround however. The IE zoomfactor is controlled in the registry key. Setting the registry key there controls what the web browser control sets its zoom to.
var key = "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Internet Explorer\\Zoom\\";
Registry.SetValue(key, "ZoomFactor", 0x186a0, RegistryValueKind.DWord); //0x1860a is 100%

Related

Windows Application Form : How to set the zoom level of the webBrowser?

I was looking for a way to set the zoom level of my Windows Form Application in which I have navigate some urls. So I open the urls using:
webBrowser1.Navigate("url")
and I want to set the zoom level of the webBrowser1 that depends on the url I have chosen. I have seen the below link but none of them have worked :
https://social.msdn.microsoft.com/Forums/en-US/69f57099-428a-4b17-9b8e-c05ec269c480/zoom-inout-while-designing-forms-in-windows-forms-designer?forum=winformsdesigner&fbclid=IwAR3aZdGsVf4lE5Lw9E3x7grp1dYoWZIUHmhVzJmU8S2BzzwnzaV20Hv5HoE
https://weblog.west-wind.com/posts/2016/Aug/22/Detecting-and-Setting-Zoom-Level-in-the-WPF-WebBrowser-Control
Problems having content in webbrowser scale automatically in Windows Form Application
Please try this
webBrowser1.Document.Body.Style = "zoom:50%";

C# Webbrowser: Specifying Max-Device-Width

I am working on a Web application that uses the Windows Forms C# Webbrowser to take screenshots of Web pages and save them for archiving purposes.
I am running into an issue with pages that use max-device-width in CSS media queries for responsive layout.
Apparently the max-device-width for the Webbrowser control defaults to 1024 px which causes certain CSS rules to fire resulting in layout issues.
Using max-width in the media queries would probably fix this, but would have the undesired effects when resizing the browser window on desktop browsers.
Is there some way of specifying the max-device-width of the Webbrowser?

Creating web browsers

From what I know, browsers that are based on WebKit have been built around the open source webkit project after they downloaded it and built it, so if one were to build a browser around the Trident rendering engine/Internet Explorer's rendering engine, would you-
Download Trident from somewhere, build it and add it to your project, or;
Add a System.Windows.Forms.WebBrowser Control to your Form and use that?
I believe that the System.Windows.Forms.WebBrowser control is indeed based on IE's Trident engine. however it is highly limited in what it can and can't do, by default.
You can however modify application specific settings for your browser to enable features through the control.
An example of this is that the WebBrowser control, by default, renders using the lowest setting supported by the version of IE installed on the machine, so for example if you have IE9 installed, the WebBrowser control will render in IE7 compatibility mode, but you can make it render using IE9 standards based mode if you change/add some settings to the registry.
Take a look at implementing/modifying Internet Feature Controls here:
http://msdn.microsoft.com/en-us/library/ee330720%28v=vs.85%29.aspx
On another note, I think you'd be hard pushed to find a download for Trident. Being a Microsoft product, my guess is that it's a closely guarded, closed source, secret! - However of you do find a download for it, I'd be very interested to know more! :-)

Internet Explorer PDF Reader

I apologize for the length of this question, but some background explanation is required.
Background:
I'm working on an internal web application that will display a pdf in an iframe. Adobe Reader X offers a "Read Mode" for displaying the pdf in the browser. This removes the shell and adds a menu box to the bottom of the pdf when the mouse is over the "middle center". In versions prior to X you could use JavaScript to modify the toolbar menu items.
What I Need:
I need to display the pdf in "Read Mode" AND remove all menu items. The computers that are to run this app are basically a kiosk and are literally a computer, monitor and mouse. No printers, no keyboard, no other interactivity.
My question is this:
How can I load a pdf for reading in internet explorer, and disable all interaction except scrolling. That is, no menus, no context menu, and no "shadow bar" when the bottom center is moused over. I've been searching for alternatives to Adobe, and there are some great ones, but the ones I've found that have a browser plugin, do not have a plugin for IE.
If someone know a way to just load the PDF Contents that would be an even better route.
More Information:
If it helps, while this is being built for Internet Explorer, the web-page will be loaded into a windows form that is just a full-screen browser control.
Other things I've tried:
I have also tried positioning a transparent iFrame on top of the pdf iFrame, covering only the displayed content, but leaving the scrollbars intact. This worked perfect if I loaded anything BUT a pdf. If I loaded any other website then it worked as expected (except the scroll wheel of course doesn't scroll the webpage). If a pdf was loaded, then all that would appear is a white square. Use the dev toolbar to remove the transparent iFrame and the PDF looks good.
I've found a good partial solution. A product called PDFObject.
Using it, I can add the following JavaScript to my page:
function embedPDF() {
var myPDF = new PDFObject({
url: 'PathToPdf.pdf',
pdfOpenParams: {
scrollbars: '1',
toolbar: '0',
statusbar: '0',
messages: '0',
navpanes: '0'
}
}).embed('DivToLoadPdfInto');
}
window.onload = embedPDF;
This will embed the pdf into a div and remove the toolbar, statusbar, message, navpanes, but still allow scrollbars. This prevents the shadow box menu from appearing, which is great!
Users can still right-click on the pdf so I'll try the standard Right-Click blockers in JavaScript and edit if I can get something to work.
Edit:
A good resource for URL Parameters can be found here.
Ok, so I have come up with a final solution.
Needs:
Load PDF in iFrame in "Reader Mode" but with no shadow bar
PDF Context Menu should be disabled
Addressing the first need is easy with some caveats. Set the source of the iFrame to "pathToPdf/document.pdf#toolbar=0&navpanes=0". The caveats here are that (in IE at least) once this breaks, then the browser needs to be closed and re-opened to work again. So, what can break it?
User right clicks and opens the navigation pane buttons.
User presses the escape button on the keyboard.
The webpage is loaded into the browser control of a windows form, and luckily once broken there it works fine without closing and reopening. Could still be a problem though for the PDF being viewed. I don't have to worry about the escape key, because the app is running on a KIOSK(basically) and there is no keyboard, only a mouse.
Disabling the context menu has proved to be the most difficult thing to do. The web browser control has a "IsWebBrowserContextMenuEnabled" property that when set to "False" will disable the context menu for the browser. Probably because the adobe reader is a plugin, this does not effect the PDF. With Reader X there is no registry setting (that I could find) or JavaScript method, or general setting that will disable context menu.
I was ready to give up when I remembered something. This is a kiosk, and there is no need for the right mouse button. So the solution; modify the registry and turn off the right click for the internal OS. To do that simply open regedit and goto:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
Find (or create if it is not there) a DWORD key named "NoViewContextMenu".
A value of 1 will disable right clicking, 0 will enable.
Summary:
Use "pathToPdf/document.pdf#toolbar=0&navpanes=0"
Disable right click in windows registry
Edit:
The registry hack only disables the right mouse button in windows explorer. We are having no luck in finding a good software solution, so we are left with either writing our own custom mouse drivers or simply popping open the mice and removing the physical trigger mechanism.

ASP.NET Disable page formatting when not full screen

I have a web application on VS2005 using C#.
Whenever my webpage does not open up in full screen, the icons and labels will automatically adjust to fit the width of the windows, making the buttons and icons disoriented.
Is there any way to disable this or enable the format to be fixed regardless if the windows is full screen or not?
This would be hard to do. You could use a function in javascript to chceck if browser is in full screen. Then you woud have to do this in intervals to make sure that this is or is not true.
if (screen.width == window.innerWidth && screen.height == window.innerHeight) {
// web browser full screen
}
Based on that you could make another screen CSS template that you could apply based on that condition. Then you could make your site apply another layout.
Another approach I would reccoment is to make your CSS layout in a way that you would be satisfied with it with any browser size.
You can use CSS to set width (which will be fixed) or min-width (layout will not shrink to less). min-width is not supported on older versions of IE.
In both cases if the browser window is smaller (or the available space – if something like history is opened down the side) than this then horizontal scrolling will be alloed.
However consider that many users have very wide screens these days, far too wide for comfortable reading if a browser is maximised.

Categories