-
Jul 12th, 2020, 09:28 AM
#1
Thread Starter
Addicted Member
[RESOLVED] [DONE] WebBrowser - Zooming - SendKeys
I thought this would be a straight-forward solution using the webBrowser
To zoom in/out, you would use CTRL+{Add key} and CTRL+{Subract key) on your keyboard
So, I tried this code
Code:
web1.Focus()
SendKeys.SendWait("^{ADD}")
It doesn't work, and the control has no direct zoom features from what i can tell because its a wrapper.
So, that means I can only do this with Sendkeys or API.
Not sure what API to use.
Anyone have any ideas on how to make this simple and painless?
Last edited by pixelink; Jul 13th, 2020 at 06:02 PM.
-
Jul 12th, 2020, 09:53 AM
#2
Thread Starter
Addicted Member
Re: WebBrowser - Zooming - SendKeys
Apparently, sendkeys doesn't work on my webbrowser control at all.
I tried several other sendkey commands that work elsewhere in my app (RichTextBox)
So, now I guess I need an API solution.
I have tried a couple but doesn't work.
Onward I go researching
-
Jul 12th, 2020, 11:23 AM
#3
Re: WebBrowser - Zooming - SendKeys
Hi Pixelink,
If you want to change your webbrowser control's zoom setting, have you tried this:
Code:
WebBrowser1.Document.Body.Style = "zoom:300%"
?
yours,
Peter Swinkels
-
Jul 12th, 2020, 05:31 PM
#4
Thread Starter
Addicted Member
Re: WebBrowser - Zooming - SendKeys
Originally Posted by Peter Swinkels
Hi Pixelink,
If you want to change your webbrowser control's zoom setting, have you tried this:
Code:
WebBrowser1.Document.Body.Style = "zoom:300%"
?
yours,
Peter Swinkels
@Peter
Thanks for the reply.
But I get Error saying Document not a member
As far I as know, this WebView2 Compatible is a wrapper.
I need to use this because the regular WebBrowser control doesn't display javascript (I get JS errors)
So, I need a webbrowser that will display modern websites today.
The Standard WBrowser is not compatible to for what i need.
I am still researching, trying code and API's, but still haven't found a solution yet that isn't too complicated to setup.
Thanks
-
Jul 13th, 2020, 10:18 AM
#5
Re: WebBrowser - Zooming - SendKeys
Originally Posted by pixelink
@Peter
Thanks for the reply.
But I get Error saying Document not a member
As far I as know, this WebView2 Compatible is a wrapper.
I need to use this because the regular WebBrowser control doesn't display javascript (I get JS errors)
So, I need a webbrowser that will display modern websites today.
The Standard WBrowser is not compatible to for what i need.
I am still researching, trying code and API's, but still haven't found a solution yet that isn't too complicated to setup.
Thanks
Hello pixelink,
Sorry to hear that. Did you load a document and if so did you make sure it was finished loading before trying to change its zoom setting? Webview2? Are you using the webbrowser control provided by the .net framework? If not that could explain why the suggested code isn't working.
If you just need a modern webbrowser why don't you just download and install one? There are several available such as Firefox and Chrome. What version of Windows are you using?
Personally I don't know any API functions that would suit your needs and I would avoid messing with those unless there is no other way. They're pretty low-level functions that make your program unstable if used incorrectly.
Perhaps you could post the relevant code here?
yours,
Peter Swinkels
Last edited by Peter Swinkels; Jul 16th, 2020 at 02:58 AM.
Reason: typo
-
Jul 13th, 2020, 10:50 AM
#6
Thread Starter
Addicted Member
Re: WebBrowser - Zooming - SendKeys
Originally Posted by Peter Swinkels
Hello pixelink,
Sorry to hear that. Did you load a document and if so did you make sure it was finished loading before trying to change its zoom setting? Webview2? Are you using the webbrowser control provided by the .net framework? If not that could explain why the suggested code isn't working.
If you just need a modern webbrowser why don't you just download and install one? There are several available such as Firefox and Chrome. What version of Windows are you using?
Personally I don't know any API functions that would suit your needs and I would avoid messing with those unless there is no other way. They pretty low-level functions that make your program unstable if used incorrectly.
Perhaps you could post the relevant code here?
yours,
Peter Swinkels
I have done some research on this.
The default WebBrowser that comes in VS2019 doesn't support JS code unless you tweak the registry, suppress, use APi or another control.
It uses the IE you have on your system.
However, through NPM (Nuget), Microsoft offers a more compatible web browser control called WebView2
It supports JS and all modern browser. It is a wrapper for microsoft's Edge browser.
I don't need to download another browser. I have Chrome, IE and Edge
The issue is the default Webbrowser
Since, its a wrapper, It looks like I have to turn to API to use zoom, which I am still researching.
Last edited by pixelink; Jul 13th, 2020 at 11:11 AM.
-
Jul 13th, 2020, 10:53 AM
#7
Re: WebBrowser - Zooming - SendKeys
Originally Posted by pixelink
I have done a lot of research on this.
The default WebBrowser that comes in VS2019 doesn't support JS code.
However, through NPM (Nuget), Microsoft offers a more compatible web browser control called WebView2
It supports JS and all modern browser. It is a wrapper for microsoft's Edge browser.
I don't need to download another browser. I have Chrome, IE and Edge
The issue is that the default Webbrowser control doesn't support JS... thus the JS errors.
Since, its a wrapper, I have to turn to API which I am still researching.
Hello eurostar_italia,
Okay, good luck.
yours,
Peter Swinkels
-
Jul 13th, 2020, 11:26 AM
#8
Thread Starter
Addicted Member
Re: WebBrowser - Zooming - SendKeys
I did come across some websites that suggested enabling Active (JS) Scripting in the Internet Options in the browsers
All of my browsers are enabled and the webbrowser still displays JS errors... so its not working.
That is the only problem with going to google. I do find 90% of my answers there, but sometimes you get bad advice and incorrect code examples.
That is one of the biggest reasons I come to this forum... because there are experts here who can help.
So, onward my research goes.
-
Jul 13th, 2020, 11:48 AM
#9
Thread Starter
Addicted Member
Re: WebBrowser - Zooming - SendKeys
Update on Zooming in WebView2
According to MS...
https://docs.microsoft.com/en-us/mic...forms-webview2
Zoomfactor is a method.
However, itellisense popup... there is no member ZoomFactor, or at least its not visible in my code popup.
So, another issues i have to figure out.
-
Jul 13th, 2020, 12:10 PM
#10
Thread Starter
Addicted Member
Re: WebBrowser - Zooming - SendKeys
BTW... here is the link that helps with getting WEBView working in WinForms
https://stackoverflow.com/questions/...14446#38514446
What I don't understand is that zoom is a method, but it isn't available to me in code-popup or properties.
Not sure why yet
-
Jul 13th, 2020, 04:37 PM
#11
Re: WebBrowser - Zooming - SendKeys
Originally Posted by pixelink
I thought this would be a straight-forward solution using the webBrowser
To zoom in/out, you would use CTRL+{Add key} and CTRL+{Subract key) on your keyboard
So, I tried this code
Code:
web1.Focus()
SendKeys.SendWait("^{ADD}")
It doesn't work, and the control has no direct zoom features from what i can tell because its a wrapper.
So, that means I can only do this with Sendkeys or API.
Not sure what API to use.
Anyone have any ideas on how to make this simple and painless?
Note that changing zoom factor could cause window.innerWidth/innerHeight and page layout to change. A zoom factor that is applied by the host by calling ZoomFactor becomes the new default zoom for the WebView. This zoom factor applies across navigations and is the zoom factor WebView is returned to when the user presses ctrl+0. When the zoom factor is changed by the user (resulting in the app receiving ZoomFactorChanged), that zoom applies only for the current page. Any user applied zoom is only for the current page and is reset on a navigation. Specifying a zoomFactor less than or equal to 0 is not allowed. WebView also has an internal supported zoom factor range. When a specified zoom factor is out of that range, it will be normalized to be within the range, and a ZoomFactorChanged event will be fired for the real applied zoom factor. When this range normalization happens, the ZoomFactor property will report the zoom factor specified during the previous modification of the ZoomFactor property until the ZoomFactorChanged event is received after webview applies the normalized zoom factor
https://docs.microsoft.com/en-us/mic...sandzoomfactor
https://docs.microsoft.com/en-us/mic...2/releasenotes
-
Jul 13th, 2020, 04:47 PM
#12
Re: WebBrowser - Zooming - SendKeys
from m$, not quite sure on the comment.
Generally we don't want to expose the controller because the WebView2 control expects to be the only one interacting with it and to allow otherwise would make things like focus and so on much more complicated. Most APIs on the controller we connect up to WinForms or WPF and don't need to wrap and expose directly off of the WebView2 class. Zoom isn't one of those though and we need to expose that directly.
-
Jul 13th, 2020, 05:19 PM
#13
Thread Starter
Addicted Member
Re: WebBrowser - Zooming - SendKeys
Originally Posted by ident
from m$, not quite sure on the comment.
Generally we don't want to expose the controller because the WebView2 control expects to be the only one interacting with it and to allow otherwise would make things like focus and so on much more complicated. Most APIs on the controller we connect up to WinForms or WPF and don't need to wrap and expose directly off of the WebView2 class. Zoom isn't one of those though and we need to expose that directly.
I read this on their site
And, that is what confused me.
They don't really come out and expose any way to code zoom, but they just mention that their is a zoomfactor method.
Of course I have been searching everywhere for code that illustrates this method... none.
So, if I read it really slow, I seems they are saying that zoom is only controlled by the user using their browsers zoom functionality.
That would explain not being able to use Sendkeys. That normally works on most things.
So, do you think I have basically reached the end of this? There is no zoomfactor that I can code for the WebBrowser or WebView2 controls?
Thanks for the input.
-
Jul 13th, 2020, 05:49 PM
#14
Re: WebBrowser - Zooming - SendKeys
You are using WebView2 correct? You need to remember (am keep in mind i'v not moved over to core) that visual basic and core are still in transition. I was talking to Christian Nagel a few months back who is massively involved with the core development and lots of even basic templates at the time had not been released.
I can't say what you are doing is right or wrong because I personally have not made any attempt to migrate to core. My point is if you are going to use structures that have only recently been implemented, hardly worked on or what ever then you need to expect these instances where things will not work.
It could be it has been fully transitioned but faulty. *shrug* I can't answer and I do not think many people here have moved to core yet?
-
Jul 13th, 2020, 06:01 PM
#15
Thread Starter
Addicted Member
Re: WebBrowser - Zooming - SendKeys
Originally Posted by ident
You are using WebView2 correct? You need to remember (am keep in mind i'v not moved over to core) that visual basic and core are still in transition. I was talking to Christian Nagel a few months back who is massively involved with the core development and lots of even basic templates at the time had not been released.
I can't say what you are doing is right or wrong because I personally have not made any attempt to migrate to core. My point is if you are going to use structures that have only recently been implemented, hardly worked on or what ever then you need to expect these instances where things will not work.
It could be it has been fully transitioned but faulty. *shrug* I can't answer and I do not think many people here have moved to core yet?
Yeah, I know it is a preview implementation and MS even said some things could change.
But, am okay with that for now as the app i am making is only for me anyways.
So, if it breaks then hopefully that just means there is an updated WebView2.
The zoom isn't critical, but I was hoping to use a button to control it so I didn't have to use a shortcut keys.
So, I guess I will close this thread.
Thanks for your input!!
-
Jul 15th, 2020, 11:12 AM
#16
Thread Starter
Addicted Member
Re: WebBrowser - Zooming - SendKeys
MAJOR UPDATE:
1) You have to use the 0.9538 pre-release version from NPM
2) You MUST install MS Edge Canary (in Beta)... the WebView2 doesn't work on the current version of Edge that is in Windows 10
3) You MUST set project to either ANY CPU or x86
Then zoom factor is available.
REMEMBER... this WebView2 is in preliminary development and shouldn't be used in production.
The app I am making is for me, so I am not picky if it breaks
So, now I consider this thread SOLVED!!
Thanks everyone.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|