Yesterday, I presented an approach to manage to display an image in the old Web Browser control so it was resized to fit a given box while retaining its aspect ratio, you can read the details by reviewing
I figured I quickly demonstrate the required code to do the same in the new Modern Web Browser control since the is a better simpler approach that we can employ which reduces the HTML/CSS required.
Below is the code required:
Private Sub Form_Current()
Dim sJS As String
If IsNull(Me.Imagepath) = False Then
sJS = "document.open();" & _
"document.write('<html><head></head><body><img src=""" & Replace(Me.Imagepath, "\", "\\") & """ height=""200"" width=""200"" style=""object-fit:contain;""></body></html>');" & _
"document.close();"
Me.EdgeBrowser0.ExecuteJavascript sJS
Else
sJS = "document.open();" & _
"document.write('<html><head></head><body></body></html>');" & _
"document.close();"
Me.EdgeBrowser0.ExecuteJavascript sJS
End If
End Sub
Yes, the code could be optimized better, so feel free to do so, this was solely mean to demonstrate the approach and HTML/CSS required to make it all work. I leave the fine tuning to your capable hands.
Hope this help a few of you out there.
Remember the following was for web images. The Modern Web Browser control is VERY fickle (still LOTS of work the Dev Team needs to do on this control! Truly a shame the current state of this control) when it comes to loading local files/images and requires more massaging to do so, an article for another day! That isn’t to say some of the alternate approaches to coding the browser control don’t have merit, but rather that the proposed HTML will not do what is being asked in the original question.