r/visualbasic • u/mudderfudden • Jan 04 '24
VB.NET Help How can I pass a WebView2 Control as an argument?
Here's the gist. I have four WebView2 Controls and my code is long, I feel it can be shortened if there's a way to use a function to pass the appropriate WebView2 control in a function and shorten it.
Here are my WebView2 Controls:
- wvScreenA
- wvScreenB
- wvScreenC
- wvScreenD
An example of what I want to do with all of my WebView2 controls.
wvScreenA.Top=0
wvScreenA.Left=0
wvScreenA.Height=1080
wvScreenA.Width=1920The thought is to do something like this (this is pseudocode):
Private Sub FullScreen (CurrentScreen as WebView2)
CurrentScreen.Top=0
CurrentScreen.Left=0
CurrentScreen.Height=1080
CurrentScreen.Width=1920
End SubCall the function for each control:
FullScreen (wvScreenA)
FullScreen (wvScreenB)
FullScreen (wvScreenC)
FullScreen (wvScreenD)This is what I've tried, which seems to not work at all:
Private Sub FullScreen (CurrentScreen as WebView2)
Also,
Private Sub FullScreen (ByRef CurrentScreen as WebView2)
Any thoughts on how to achieve what I'm looking to do?
2
u/veryabnormal Jan 05 '24 edited Jan 05 '24
Set the WindowSate to maximised instead?
Edit: Oh. Sorry that would be for a Form but you are sizing the webview. Itself.
You could use the Dock property of the webview? That would work with any screen size.
1
u/RJPisscat Jan 05 '24 edited Jan 05 '24
If you call the function for each control and it works, you'll have the top of the Z-Order as the topmost control. However, in another post you said
isn't producing the desired results. Is it working now?
The two versions of the function that you posted are functionally identical. You don't need a With; it does not change any functionality.
1
u/[deleted] Jan 04 '24
[removed] — view removed comment