Size of Window and scroll bar

  • Thread starter =?iso-8859-1?Q?Jan_Weing=E4rtner?=
  • Start date
?

=?iso-8859-1?Q?Jan_Weing=E4rtner?=

Hi.

If the horizontal scrollbar of a window is active,
how can i retrieve the entire width of the window - means the sum of
the visible _and_ the invisible client area?

best regards and thanks,
Jan
 
S

Stoitcho Goutsev \(100\)

Jan,

There more than one ways to implement scrolling and as much ways to get the
information you are looking for.

I think however you are talking about the autoscroll feature provided by
some of the windows forms controls and I hope you are using .NET 2.0.

If this is correct assumption there is an idea how to get the virtual size
of the client area:

Size size = new Size();

size.Width = (!this.HScroll) ? this.ClientSize.Width :
this.HorizontalScroll.Maximum + 1;

size.Height= (!this.VScroll) ? this.ClientSize.Height :
this.VerticalScroll.Maximum + 1;

MessageBox.Show(size.ToString());
 
D

Dave Sexton

Hi Jan,

Try using the DisplayRectangle property.

DisplayRectangle provides the scrolling client rectangle for Controls derived from ScrollableControl, such as ContainerControl and
Panel. Form and UserControl both derive from ContainerControl, for example, so the DisplayRectangle property should behave the same
for them as well.
 
?

=?iso-8859-1?Q?Jan_Weing=E4rtner?=

Hi.
size.Width = (!this.HScroll) ? this.ClientSize.Width :

The property HScroll is always false, despite the scrollbar is visible.
I don't know why.
The ClientSize property gives me only the size of the _visible_ rectangle.

best regards,
Jan
 
?

=?iso-8859-1?Q?Jan_Weing=E4rtner?=

Hi.
Try using the DisplayRectangle property.

The DisplayRectangle property gives me only the size of the _visible_ rectangle.
I'm looking for the invisible one.

best regards,
Jan
 
?

=?iso-8859-1?Q?Jan_Weing=E4rtner?=

Hi.
If the horizontal scrollbar of a window is active,
how can i retrieve the entire width of the window - means the sum of
the visible _and_ the invisible client area?

Maybe some more information: I have a simple form with a WebBrowser control (Dock = Fill)
and i want to increase the width of the form to disable the horizontal scroll bar and
to show the complete control content.

best regards and thanks,
Jan
 
D

Dave Sexton

Hi Jan,

The WebBrowser control does not derive from ScrollableControl. As I mentioned in my previous post, it is the ScrollableControl
class that overrides the DisplayRectangle property to provide meaningful data, so I'm not suprised that the DisplayRectangle
property behaves differently for the WebBrowser control.

To retrieve the display rectangle for the WebBrowser control you'll have to use the DOM:

Measuring Element Dimension and Location on MSDN (illustration):
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/om/measuring.asp

You can access the "body" element using the following C# code where "browser" is a variable of Type WebBrowser:

HtmlElement body = browser.Document.Body;
 
S

Stoitcho Goutsev \(100\)

Jan,



I read the info tha you provided in one of your other posts. If the
WebBrowser control is docked fill most likely the scrollbars come from the
control itself not form the form. Checking HScroll and VScroll on the form
will probably return always false unless there is some other control
positioned in a way that the scrollbars appear.

..NET part of the WebControl is pretty shallow. The class is almost only a
wrapper around the IE ActiveX control. Whether or not you can get the
scrollbars settings and the interprettation of these settings is depends on
the ActiveX control, which I'm not familiar with. The only thing that I can
see in the docs regarding this control is that you can find out whether the
scrollbars are visible reading the ScrollBarsEnabled property, but this is
not big of a help.



I'd suggest reading docs regarding WebBrowaser ActiveX control to see if the
info you are interested in is provided by the control and trying to find out
how the get that info directly from the ActiveX control. I see that there is
ActiveXInstance property that probably can be used for this.
 
?

=?iso-8859-1?Q?Jan_Weing=E4rtner?=

Dave,

i have checked some body attributes like "clientWidth" and "offsetWidth".
But they also give me only the visible width of the control.

best regards,
Jan
 
?

=?iso-8859-1?Q?Jan_Weing=E4rtner?=

Hi Dave,
You didn't look hard enough!

Try scrollWidth and scrollHeight, which are both listed in the diagram to which I linked.

Sorry, but i don't see, how scrollWidth can help. It gives me the _visible_ width of a
tag. So it's the same value as clientWidth for the body tag.
What i need is the width of the invisible area which is "hidden behind" the scroll bar.


| visible width | invisible width |
| | |
|---------------------------|-------------------
| Scroll bar |
 
D

Dave Sexton

Hi Jan,

Why would clientWidth and scrollWidth return the same value? It doesn't make much sense for IE to have two properties that always
represent the same thing.

Try scrollWidth and you should be pleasantly suprised.
 
?

=?iso-8859-1?Q?Jan_Weing=E4rtner?=

Hi Dave,
Why would clientWidth and scrollWidth return the same value?

Like already mentioned: it applies to the body tag.
Try scrollWidth and you should be pleasantly suprised.

I already have. Otherwise i would not post it.
But maybe there is a bug in my code:

scrollWidth = browser.Document.Body.GetAttribute("scrollWidth");
clientWidth = browser.Document.Body.GetAttribute("clientWidth");

The results are:

scrollWidth = 226
clientWidth = 226

If i look at the diagramm at the msdn page the meaning of
scrollWidth is clear. It's only the _visible_ width. So for
the body tag scrollWidth is equal to clientWidth - even if
there is no horizontal scroll bar.

best regards,

Jan
 
D

Dave Sexton

Hi Jan,

(Sorry for the e-mail, I'm using a different computer right now and I accidentily clicked "Reply" :)

I think you have misinterpreted a line in the article on MSDN. It states the following for the scrollWidth property:

"The width is the distance between the left and right edges of the object's visible content."

By "visible content" they are referring to the "visibility" of the "content", not the display rectangle. In other words, if there
is content that isn't visible, e.g. a hidden tag, then it won't count towards the total size of the scrollWidth property.

There is an example right on the page that proves that it works. Try it. I also just tested it myself and it worked just fine for
me.

For your own test make sure there are scroll bars on the body itself and not a nested tag such as a div.

Here's my test:

<html>
<head></head>
<body>
<div id="info"></div>
<nobr>
Content Content Content Content Content Content Content Content Content Content Content
Content Content Content Content Content Content Content Content Content Content
Content Content Content Content Content Content Content Content Content Content Content
Content Content Content Content Content Content Content Content Content Content Content
</nobr>
</body>
<script>
window.onresize = window_onresize;

function window_onresize()
{
GetInfo();
}

function GetInfo()
{
info.innerHTML = document.body.scrollWidth + "<br />";
info.innerHTML+= document.body.clientWidth + "<br />";
}

GetInfo();
</script>
</html>
 
?

=?iso-8859-1?Q?Jan_Weing=E4rtner?=

Hi Dave!

Ok, now i get it. It was a table element (and not the body tag)
which has defined the scroll width.

thanks and best regards,
Jan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top