ControlCollection.GetShapeForControl(Control) Methode

Definition

Ruft das zugrunde liegende Shape für das angegebene Steuerelement ab.

public Microsoft.Office.Interop.Word.Shape GetShapeForControl (System.Windows.Forms.Control control);

Parameter

control
Control

Das Steuerelement in der ControlCollection-Instanz, aus dem Sie das Shape abrufen möchten.

Gibt zurück

Shape

Das zugrunde liegende Shape für das angegebene Steuerelement.

Beispiele

Im folgenden Codebeispiel wird ein Button zum Dokument hinzugefügt. Anschließend wird die-Methode verwendet, GetShapeForControl um die Position des-Steuer Elements aus dem zugrunde liegenden-Element zu erhalten Shape .

private void WordGetShape()
{
    Microsoft.Office.Tools.Word.Controls.Button testButton =
        this.Controls.AddButton(10, 10, 50, 25,	"testButton");

    Microsoft.Office.Interop.Word.Shape buttonShape =
        this.Controls.GetShapeForControl(testButton);

    if (buttonShape != null)
    {
        MessageBox.Show("The following properties can be cached in the" +
            "\n" + "document to enable you to recreate the control:" +
            "\n\n" + "Height: " + buttonShape.Height.ToString() +
            "\n" + "Width: " + buttonShape.Width.ToString() + "\n" +
            "Top: " + buttonShape.Top.ToString() + "\n" +
            "Left: " + buttonShape.Left.ToString());
    }
}
Private Sub WordGetShape()
    Dim testButton As Microsoft.Office.Tools.Word.Controls.Button = _
        Me.Controls.AddButton(10, 10, 50, 25, "testButton")

    Dim buttonShape As Microsoft.Office.Interop.Word.Shape = _
            Me.Controls.GetShapeForControl(testButton)

    If buttonShape IsNot Nothing Then
        MessageBox.Show("The following properties can be cached in the" & _
            vbCrLf & "document to enable you to recreate the control:" _
            & vbCrLf & vbCrLf & "Height: " & buttonShape.Height _
            & vbCrLf & "Width: " & buttonShape.Width _
            & vbCrLf & "Top: " & buttonShape.Top _
            & vbCrLf & "Left: " & buttonShape.Left)
    End If
End Sub

Hinweise

Wenn das Wrapping Format des-Steuer Elements auf in Zeilen mit Textfestgelegt ist, GetShapeForControl gibt die Methode zurück null .

Gilt für