Share via


ControlCollection.GetShapeForControl, méthode

Reçoit le Shape sous-jacent pour le contrôle spécifié.

Espace de noms :  Microsoft.Office.Tools.Word
Assembly :  Microsoft.Office.Tools.Word (dans Microsoft.Office.Tools.Word.dll)

Syntaxe

'Déclaration
Function GetShapeForControl ( _
    control As Control _
) As Shape
Shape GetShapeForControl(
    Control control
)

Paramètres

Valeur de retour

Type : Microsoft.Office.Interop.Word.Shape
Shape sous-jacent pour le contrôle spécifié.

Notes

Si le style d'habillage du contrôle a la valeur Aligné sur le texte, la méthode GetShapeForControl retourne nullune référence null (Nothing en Visual Basic).

Exemples

L'exemple de code suivant ajoute un Button au document, puis utilise la méthode GetShapeForControl pour obtenir l'emplacement du contrôle à partir de son Shape sous-jacent.

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

Sécurité .NET Framework

Voir aussi

Référence

ControlCollection Interface

Microsoft.Office.Tools.Word, espace de noms