Metoda ControlCollection.GetShapeForControl —

Pobiera podstawowych Shape dla danej kontrolki.

Przestrzeń nazw:  Microsoft.Office.Tools.Word
Zestaw:  Microsoft.Office.Tools.Word (w Microsoft.Office.Tools.Word.dll)

Składnia

'Deklaracja
Function GetShapeForControl ( _
    control As Control _
) As Shape
Shape GetShapeForControl(
    Control control
)

Parametry

Wartość zwracana

Typ: Microsoft.Office.Interop.Word.Shape
Podstawowa Shape dla danej kontrolki.

Uwagi

Jeśli styl otaczania formantu jest ustawiona na Równo z tekstem, GetShapeForControl metoda zwraca nullodwołanie o wartości null (Nothing w języku Visual Basic).

Przykłady

Poniższy kod dodaje Button do dokumentu, a następnie używa GetShapeForControl metody, aby położenie formantu z jego podstawowych Shape.

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

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

ControlCollection Interfejs

Przestrzeń nazw Microsoft.Office.Tools.Word