After the last WebBrowser.Document.Write(), I call my scroll to bottom
function. Then I call it again with a button press. The first time
goes near the bottom. The second call goes right to the bottom. So,
I put a size checker in the scroll to bottom function. It appears the
size of the webpage GROWS by 30 pixels between the two calls, even
though nothing has changed in the webpage between them. This growth
explains the incorrect scrolling amount.
Ok, this is what happens, when I WebBrowser.Document.Write() some HTML
of <SPAN> or <DIV> with a CSS class that has "white-space: pre;" with
text that has at least one carriage return in it:
1. Immediately after the Write():
WebBrowser.Document.Window.Size = {Width=1325, Height=450}
2. After the Write() is done, "after some period of time":
WebBrowser.Document.Window.Size = {Width=669, Height=720}
Note that in #1, the width is very wide. WebBroser thinks the
carriage returns don't exist, and the page is very wide! (remember we
are using 'pre'.) Then, "after some period of time", it fixes it, and
puts the carraige returns in, and thus the width becomes normal, and
the height changes.
So, if you attempt to scroll to the bottom in #1, it does scroll to
the bottom of the size it THINKS it is, but as soon as it is actually
rendered, it's not far enough.
The only thing left is to define "after some period of time". #1. is
called after the Write() call. #2. is called via button in the form,
by manual click. What happens between #1 and #2? I thought maybe
it's just some time, so I waited a second in #1, and THEN scrolled to
the bottom, but no cigar (it still hasn't 'fixed' the size, yet). I
thought maybe it is the WM_PAINT message. But, I put the thread to
sleep, and waited for some time, and I still get #1 behaviour, BUT,
since I am in the main thead, and I put it to sleep, then I am
delaying WM_PAINT.
I believe I must allow WM_PAINT to render the form, then it corrects
the problem, and THEN I have to scroll to the bottom. So, I went to
use Control.Update(), but this doesn't work. It "Causes the control
to redraw the invalidated regions within its client area", which
sounds like it forces an update. But, then, Control.Refresh() claims
it "Forces the control to invalidate its client area and immediately
redraw itself and any child controls", so it sounds like the one to
use. BUT, WebBroswer.Refresh() ERASES THE CONTENTS of the control!
Microsoft, please fix these damned bugs. So far I am on a chain of 5
bugs where each led to the next.
My question:
How can I force a control to process WM_PAINT? Looks like the only
solution is DllImport to Win32's UpdateWindow().
Zytan