ControlCollection.GetShapeForControl(Control) Method

Definition

Gets the underlying Shape for the specified control.

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

Parameters

control
Control

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

Returns

The underlying Shape for the specified control.

Examples

The following code example adds a Button to the document, and then uses the GetShapeForControl method to get the location of the control from its underlying Shape.

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

Remarks

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

Applies to