I have an HTMLViewer whose height I want to dynamically adjust (as the users resizes) so that the content always fits with no vertical scrollbar. So I need to know the height as the content flows around; then adjusting the viewer height can be done easily enough in the Resizing/Resized events.
Looking around I discover that:
Var hite as Integer = viewer.ExecuteJavaScriptSync ("document.body.scrollHeight")
gets me something close. But scrollHeight doesn’t include any margin setting or any allowance for a horizontal scrollbar which may want to appear. The horizontal scrollbar may appear if there is a long line of unbroken text which doesn’t wrap and which requires scrolling horizontally to view it.
I can get the top margin value with:
Var marginTop as string = viewer.ExecuteJavaScriptSync ("document.body.style.marginTop")
and similar for marginBottom but then I have to parse the string to extract the value (if any) and the suffix (cm? px? pt?) and try to convert to a common value. Then I have to detect if there is a scrollbar (and there are some clunky ways to do that).
This is all starting to feel like a hack, and although I know that hacks are sometimes all there is, I am minded to wonder if I’ve overlooked something that gets what I need more directly and simply, bearing in mind that having a short, simple event handler is always preferred.