
Originally Posted by
BooksRUs
Hopefully, this is something simple. Trying to simply set the Background Color of the webview2 page.
There is a property for it, but I can't seem to find where it is in the cWebView2 class.
There is not specific property for it on the WV2 ...
The WV2-interface is generally much more "spartan", compared to the old IE-control -
which IMO is a good thing - because the less you have to learn (about the MS-WebView2).
Instead the focus now shifts from built-in COM-methods -
to "easy reachable js-Methods- and -Properties, inside the Browser-engine"
One has to be relatively proficient with JavaScript, to make good use of the WebView2
(and that's a skill, many developers these days already have).
Below is a code-snippet, which uses javascript-property-syntax - to influence the backcolor of the document.body.
Code:
Option Explicit
Private WithEvents WV As cWebView2
Private Sub Form_Load()
Me.Visible = True 'ensure visibility of this "Parent.hWnd"
Set WV = New_c.WebView2(Me.hWnd) 'bind to the hWnd
WV.NavigateToString "<p>Hello World</p>" 'create a simple document from string-input
WV.jsProp("document.body.style.background") = "red" 'set the body.style.background-pop to red color
End Sub
Private Sub Form_Resize()
If Not WV Is Nothing Then WV.SyncSizeToHostWindow
End Sub
HTH
Olaf