Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 4
HtmlElement Class
 ClientRectangle Property
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2010/.NET Framework 4

Other versions are also available for the following:
.NET Framework Class Library
HtmlElement..::.ClientRectangle Property

Gets the bounds of the client area of the element in the HTML document.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic
Public ReadOnly Property ClientRectangle As Rectangle
C#
public Rectangle ClientRectangle { get; }
Visual C++
public:
property Rectangle ClientRectangle {
    Rectangle get ();
}
F#
member ClientRectangle : Rectangle

Property Value

Type: System.Drawing..::.Rectangle
The client area occupied by the element, minus any area taken by borders and scroll bars. To obtain the position and dimensions of the element inclusive of its adornments, use OffsetRectangle instead.

ClientRectangle will return position data only for elements that have been assigned an explicit height and width, or elements that use absolute positioning. A document is absolutely positioned if its position style is set to absolute, after which it can be positioned at any coordinate on the HTML page.

Assume you have loaded the following HTML page into a hosted instance of the WebBrowser control.

<HTML>

    <BODY>

        <DIV id="div1" style="position:absolute;top:100px;left:100px;border-      style:solid;border-width:1px;">
            Edit this text.
        </DIV>

    </BODY>

</HTML>

The following code example demonstrates retrieving this element and expanding its dimensions if the client area is less than 400 pixels wide by 50 pixels high, and also sets the DIV to the contentEditable state so that the user can input text.

Visual Basic
Private Sub EnableEditing()
    Dim Elem As HtmlElement = WebBrowser1.Document.GetElementById("div1")
    If (Not Elem Is Nothing) Then
        If (Elem.ClientRectangle.Width < 200) Then
            Elem.SetAttribute("width", "200px")
        End If

        If (Elem.ClientRectangle.Height < 50) Then
            Elem.SetAttribute("height", "50px")
        End If

        Elem.SetAttribute("contentEditable", "true")
        Elem.Focus()
    End If
End Sub
C#
        private void EnableEditing()
        {
            if (webBrowser1.Document != null)
            {
                HtmlElement elem = webBrowser1.Document.GetElementById("div1");
                if (elem != null)
                {
                    if (elem.ClientRectangle.Width < 200)
                    {
                        elem.SetAttribute("width", "200px");
                    }

                    if (elem.ClientRectangle.Height < 50)
                    {
                        elem.SetAttribute("height", "50px");
                    }

                    elem.SetAttribute("contentEditable", "true");
                    //elem.SetFocus();
                }
            }
        }

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker