ControlCollection.GetInlineShapeForControl(Control) Метод

Определение

Возвращает основной объект InlineShape для указанного элемента управления.

public Microsoft.Office.Interop.Word.InlineShape GetInlineShapeForControl (System.Windows.Forms.Control control);

Параметры

control
Control

Элемент управления в экземпляре коллекции ControlCollection, из которого необходимо получить объект InlineShape.

Возвращаемое значение

InlineShape

Основной объект InlineShape для указанного элемента управления.

Примеры

В следующем примере кода в документ добавляется, Button чтобы его стиль обтекания был встроен в текст. Затем код вызывает метод, GetInlineShapeForControl чтобы получить расположение элемента управления из его базового объекта InlineShape .

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

Комментарии

Если стиль обтекания элемента управления не установлен в строку с текстом, GetInlineShapeForControl метод возвращает значение null .

Применяется к