HtmlElement.ClientRectangle Propiedad

Definición

Obtiene los límites del área cliente del elemento en el documento HTML.

public:
 property System::Drawing::Rectangle ClientRectangle { System::Drawing::Rectangle get(); };
public System.Drawing.Rectangle ClientRectangle { get; }
member this.ClientRectangle : System.Drawing.Rectangle
Public ReadOnly Property ClientRectangle As Rectangle

Valor de propiedad

Área de cliente ocupada por el elemento, menos cualquier área tomada por bordes y barras de desplazamiento. Para obtener la posición y las dimensiones del elemento inclusivo de sus adornos, use OffsetRectangle en su lugar.

Ejemplos

Supongamos que ha cargado la siguiente página HTML en una instancia hospedada del 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>

En el ejemplo de código siguiente se muestra cómo recuperar este elemento y expandir sus dimensiones si el área de cliente tiene menos de 400 píxeles de ancho por 50 píxeles de alto y también establece en DIV el estado para contentEditable que el usuario pueda escribir texto.

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();
        }
    }
}
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

Comentarios

ClientRectangle devolverá los datos de posición solo para los elementos a los que se les ha asignado un alto y ancho explícitos, o elementos que usan posicionamiento absoluto. Un documento se coloca absolutamente si su estilo de posición se establece absoluteen , después de lo cual se puede colocar en cualquier coordenada de la página HTML.

Se aplica a

Consulte también