Sdílet prostřednictvím


ControlCollection.GetInlineShapeForControl(Control) Method

Definition

Gets the underlying InlineShape for the specified control.

public:
 Microsoft::Office::Interop::Word::InlineShape ^ GetInlineShapeForControl(System::Windows::Forms::Control ^ control);
public Microsoft.Office.Interop.Word.InlineShape GetInlineShapeForControl (System.Windows.Forms.Control control);
abstract member GetInlineShapeForControl : System.Windows.Forms.Control -> Microsoft.Office.Interop.Word.InlineShape
Public Function GetInlineShapeForControl (control As Control) As InlineShape

Parameters

control
Control

The control in the ControlCollection instance from which you want to get the InlineShape.

Returns

The underlying InlineShape for the specified control.

Examples

The following code example adds a Button to the document so that its wrapping style is inline with text. The code then calls the GetInlineShapeForControl method to get the location of the control from its underlying 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

Remarks

If the wrapping style of the control is not set to In line with text, the GetInlineShapeForControl method returns null.

Applies to