473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Scrolling WebBroswer works, but not when it has proper DOCTYPE!

I can scroll a WebBrowser to the bottom like so:

if (webControl.Document != null)
webControl.Document.Body.ScrollTop = int.MaxValue;

But, if I include a proper DOCTYPE (for XHTML 1.1 DTD) like so:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

It will not work. It doesn't scroll at all. What gives?

Zytan

Mar 28 '07 #1
17 5076
It does not work if you have a DOCTYPE at all, any DOCTYPE, even ones
that make no sense:

<!DOCTYPE html>

or

<!DOCTYPE>

So, if you make the webpage conformant, like you should, then it
cannot scroll, so you lose functionality. Great.

Zytan

Mar 28 '07 #2
I found a hack:

webControl.Select();
System.Windows.Forms.SendKeys.SendWait("{END}");

(For some reason SendKeys.Send() doesn't work, it throws an
exception.)
But, this has a problem: It needs to give focus to it.

Zytan

Mar 28 '07 #3
Another solution (almost):

webControl.Document.Window.ScrollTo(0, int.MaxValue);

But, for some reason it always scrolls one line not far enough. So,
the last line written out is not visible. Does anyone know why?

Zytan

Mar 28 '07 #4
webControl.Document.Window.ScrollTo(0, int.MaxValue);
>
But, for some reason it always scrolls one line not far enough. So,
the last line written out is not visible. Does anyone know why?
MSDN claims "If the document is not long or wide enough for this to
happen, ScrollTo will scroll through the document as far as possible
in the specified direction." It almost does this. But not quite.

Zytan

Mar 28 '07 #5
webControl.Document.Window.ScrollTo(0, int.MaxValue);
>
But, for some reason it always scrolls one line not far enough. So,
the last line written out is not visible. Does anyone know why?

MSDN claims "If the document is not long or wide enough for this to
happen, ScrollTo will scroll through the document as far as possible
in the specified direction." It almost does this. But not quite.
Wait, it DOES work. It's just on certain occasions when the last text
written out to the webpage is a specific kind, it does not work. I am
having difficulty tracking down the root of the problem, since I can
get such text to work and not-work simultaneously depending on where I
make the call.

Regarding, this IS the solution for webpages with a proper DOCTYPE to
be able to scroll.

I'm just getting really tired of tracking down MS's bugs for the past
2 or 3 days. If all the bugs were merely my own, I'd be moving a lot
faster.

Zytan

Mar 28 '07 #6
Wait, it DOES work. It's just on certain occasions when the last text
written out to the webpage is a specific kind, it does not work. I am
having difficulty tracking down the root of the problem, since I can
get such text to work and not-work simultaneously depending on where I
make the call.
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.

When I slow things down, it appears that each individual 'scroll to
bottom' after a Write() does work, the scroll bar is as far down as it
can go, and I can see the last Write() made. But, when all is done,
the very last Write() doesn't work. But, when I invoke another call
to 'scroll to bottom', it does work. Something strange is happening.
The search continues. Stay tuned.

Zytan

Mar 29 '07 #7
I found the culprit.

It happens ONLY when <DIVtags are used to write out text with the
CSS style "white-space: pre;"

But, if you write out enough stuff after this the bug may or may not
appear (although it is consistent on which it chooses). My work is
required to find out exactly when and why it occurs. It appears that
this 'sets' the bug, and something else must unset it, and I am unsure
what.

My god.

First of all, the "white-space: pre;" doesn't render properly unless I
include a proper DOCTYPE. But when I include a proper DOCTYPE, it
*refuses* to scroll in the old method
(webControl.Document.Body.ScrollTop = int.MaxValue;), so I have to use
the new method (webControl.Document.Window.ScrollTo(0,
int.MaxValue);), which works except if I use "white-space: pre;" and
<DIVat the same time.

Here's an idea for IE's developers: **Read the standards and follow
them!!!!**

Zytan

Mar 29 '07 #8
It happens ONLY when <DIVtags are used to write out text with the
CSS style "white-space: pre;"
<SPANmakes it happen, as well. So, "white-space: pre;" is the sole
culprit.

Zytan

Mar 29 '07 #9
<SPANmakes it happen, as well. So, "white-space: pre;" is the sole
culprit.
AND, the <SPANor <DIVmust have at least one carriage return in
it. If it has none, all is fine.

Zytan

Mar 29 '07 #10
Forget about trying to use <PREinstead, it introduces two carriage
returns within the <DIVtags.

So, there's no solution but to deal with the fact that MS's IE
renderer doesn't properly render "white-space: pre;"

So, I guess I have to use &nbsp; to line things up in HTML, since
"pre" is not supported properly. I wonder how much that'll increase
the size of my log files.

Zytan

Mar 29 '07 #11
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 <SPANor <DIVwith 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

Mar 29 '07 #12
BUT, WebBroswer.Refresh() ERASES THE CONTENTS of the control!

http://msdn2.microsoft.com/en-us/library/txewax99.aspx
"The Refresh method forces the WebBrowser control to reload the
current page by downloading it, ensuring that the control displays the
latest version."

That's why. Since the page doesn't exist anywhere, just in memory.

Zytan

Mar 29 '07 #13
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.
If I put Thread.Sleep(1000) before and after the Write(), I can see
the text being rendered without any carriage returns, so WM_PAINT is
being processed (well, until the delay is so long, that the message
queue being passed for 5 seconds, and Windows notices this [if you
let it notice by bugging the app] and the window stops updating until
the message queue resumes). And nothing is being 'corrected' even
after a whole second.

What I don't get is that after multiple Write() calls are done, "after
some period of time" the WebBrowser corrects the document. But not
before. What is "after some period of time"? I can set the delays to
5 seconds, and it still does not correct itself. So, this is not a
time issue. Something is happening, and I am not sure when it is
being triggered. Perhaps this corection is done in some event, like
DocumentCompleted. This is the only solution. But, when does that
know to be called? Why does it apparantly wait sometimes? This is
confusing.

Zytan

Mar 29 '07 #14
Perhaps this corection is done in some event, like
DocumentCompleted.
Nope, the DocumentCompleted event is not triggered from Write method.

Zytan

Mar 29 '07 #15
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.
After WebBrowser.Write(), the WebBrowser.Invalidated event is NOT
raised.

Wow.

http://msdn2.microsoft.com/en-us/lib...validated.aspx
"Occurs when a control's display requires redrawing."

Zytan

Mar 29 '07 #16
I can witness NO events being raised when the WebBroswer decides to
'fix' itself and render itself properly. Amazing. The only solution
is to NOT use "white-space: pre;" and use &nbps; instead to properly
format text. There is no way around MS's IE's rendering bug with the
"white-space: pre;" inside <DIVor <SPANtags with carriage
returns. What a pain.

So, now, since I am going to NOT use "white-space: pre;", I can go
back to the original scrolling method, which does not require a proper
DOCTYPE to work:

webControl.Document.Body.ScrollTop = int.MaxValue;

Zytan

Mar 29 '07 #17
So, now, since I am going to NOT use "white-space: pre;", I can go
back to the original scrolling method, which does not require a proper
DOCTYPE to work:

webControl.Document.Body.ScrollTop = int.MaxValue;
Sorry, the above method does NOT work with a DOCTYPE. So, the best
way is still to use the new method I found:

webControl.Document.Window.ScrollTo(0, int.MaxValue);

Which I assume works with no DOCTYPE, as well. But, you should have a
DOCTYPE, it's proper code.

Zytan

Mar 29 '07 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: CMAR | last post by:
I create my website using Front Page 2000. I notice that none of my pages have a DocType statement at the top. I have read that if you want IE6 to use "Standards mode" rather than the "Quirks...
0
by: pigeon | last post by:
SSL only works when ms sql server has "force encryption option" turned on... If I turn that off, and try to have the client software request encryption.. I get a ssl security error msg. The...
1
by: craigkenisston | last post by:
Hi, I'm running my asp.net website against several HTML validators. My pages have the html 4.01 strict doctype, because I wanted to avoid problems with the difference in the box model across...
2
by: Daniel Beardsley | last post by:
I have a div with some text in it and an onclick event. The onclick event only seems to fire when the user clicks the text.. not if they click the blank part of the div. This is in IE 6. The...
1
by: Ethan Strauss | last post by:
Hi, I have a C#.net Web application which calls a web service (http://eutils.ncbi.nlm.nih.gov/entrez/eutils/soap/eutils.wsdl). It has run just fine for months. Recently I started getting...
1
by: Wessman | last post by:
sending mail using function mail() only works when I'm connected to mysql. <? mail($to, $subject, "before mysql_connect()", "From: $from"); mysql_connect("localhost", $username, $password);...
0
drhowarddrfine
by: drhowarddrfine | last post by:
The Doctype or DTD Many coders get confused by all the talk of doctypes and how they affect browsers and the display of their web pages. This article will get right to the point about doctypes...
1
by: Bombtrack | last post by:
I have some javascript code that errors in FireFox, but only when I use a DOCTYPE expression at the top of the page - until I added that, it worked fine in both IE and FireFox. Here is the...
0
by: shuu | last post by:
Hi I have a application that captures the screen och sends the images to a server. I want to save the destination URL's (like: http://domain.com/dump/img.jpg) to the clipboard, but this only...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.