Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2006

Tip: Looking for answers? Try searching our database.

Size of Window and scroll bar

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jan Weingärtner - 23 Aug 2006 11:19 GMT
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
Stoitcho Goutsev (100) - 23 Aug 2006 16:01 GMT
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());

Signature

HTH
Stoitcho Goutsev (100)

> Hi.
>
[quoted text clipped - 4 lines]
> best regards and thanks,
> Jan
Jan Weingärtner - 24 Aug 2006 08:04 GMT
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
Stoitcho Goutsev (100) - 24 Aug 2006 16:26 GMT
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.

Signature

Stoitcho Goutsev (100)

> Hi.
>
[quoted text clipped - 6 lines]
> best regards,
> Jan
Dave Sexton - 24 Aug 2006 07:05 GMT
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.

Signature

Dave Sexton

> Hi.
>
[quoted text clipped - 3 lines]
> best regards and thanks,
> Jan
Jan Weingärtner - 24 Aug 2006 08:05 GMT
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
Jan Weingärtner - 24 Aug 2006 08:06 GMT
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
Dave Sexton - 24 Aug 2006 10:14 GMT
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;

Signature

Dave Sexton

> Hi.
>
[quoted text clipped - 7 lines]
> best regards and thanks,
> Jan
Jan Weingärtner - 25 Aug 2006 09:25 GMT
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
Dave Sexton - 25 Aug 2006 09:48 GMT
Hi Jan,

You didn't look hard enough!

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

MSDN supplies references on both of these properties.

scrollWidth, for instance:
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/referen
ce/properties/scrollwidth.asp


Signature

Dave Sexton

> Dave,
>
[quoted text clipped - 3 lines]
> best regards,
> Jan
Jan Weingärtner - 25 Aug 2006 12:05 GMT
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           |
-----------------------------

best regards and thanks,
Jan
Dave Sexton - 25 Aug 2006 16:22 GMT
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.

Signature

Dave Sexton

> Hi Dave,
>
[quoted text clipped - 14 lines]
> best regards and thanks,
> Jan
Jan Weingärtner - 26 Aug 2006 10:29 GMT
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
Dave Sexton - 26 Aug 2006 16:55 GMT
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>

Signature

Dave Sexton

> Hi Dave,
>
[quoted text clipped - 23 lines]
>
> Jan
Jan Weingärtner - 30 Aug 2006 10:35 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.