共用方式為


ControlCollection.GetShapeForControl 方法

取得指定之控制項的基礎 Shape

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word (在 Microsoft.Office.Tools.Word.dll 中)

語法

'宣告
Function GetShapeForControl ( _
    control As Control _
) As Shape
Shape GetShapeForControl(
    Control control
)

參數

傳回值

型別:Microsoft.Office.Interop.Word.Shape
指定之控制項的基礎 Shape

備註

如果控制項的換行樣式設為 [與文字排列],GetShapeForControl 方法便會傳回 nullnull 參考 (即 Visual Basic 中的 Nothing)。

範例

下列程式碼會將 Button 加入至文件,然後使用 GetShapeForControl 方法,從這個控制項的基礎 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());
    }
}

.NET Framework 安全性

請參閱

參考

ControlCollection 介面

Microsoft.Office.Tools.Word 命名空間