Share via


ControlCollection.GetInlineShapeForControl, méthode

Obtient le InlineShape 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 GetInlineShapeForControl ( _
    control As Control _
) As InlineShape
InlineShape GetInlineShapeForControl(
    Control control
)

Paramètres

Valeur de retour

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

Notes

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

Exemples

L'exemple de code suivant ajoute un Button au document pour que son style d'habillage soit aligné sur le texte. Le code appelle ensuite la méthode GetInlineShapeForControl pour obtenir l'emplacement du contrôle à partir de son InlineShape sous-jacent.

Private Sub WordGetInlineShape()
    Dim testButton As Microsoft.Office.Tools.Word.Controls.Button = _
        Me.Controls.AddButton(Me.Paragraphs(1).Range, 50, 25, "testButton")

    Dim buttonShape As Microsoft.Office.Interop.Word.InlineShape = _
            Me.Controls.GetInlineShapeForControl(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 & "Range: position " & _
            buttonShape.Range.Start.ToString _
            & " through " & buttonShape.Range.End.ToString _
            & vbCrLf & "Width: " & buttonShape.Width.ToString _
            & vbCrLf & "Height: " & buttonShape.Height.ToString)
    End If
End Sub
private void WordGetInlineShape()
{
    Microsoft.Office.Tools.Word.Controls.Button testButton =
        this.Controls.AddButton(this.Paragraphs[1].Range, 50, 25,
        "testButton");

    Microsoft.Office.Interop.Word.InlineShape buttonShape =
        this.Controls.GetInlineShapeForControl(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" + "Range: position " + buttonShape.Range.Start.
            ToString() + "through " + buttonShape.Range.End.ToString()
            + "\n" + "Width: " + buttonShape.Width.ToString() + "\n" +
            "Height: " + buttonShape.Height.ToString());
    }
}

Sécurité .NET Framework

Voir aussi

Référence

ControlCollection Interface

Microsoft.Office.Tools.Word, espace de noms