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
)
参数
- control
类型:System.Windows.Forms.Control
希望从中获得 Shape 的 ControlCollection 实例中的控件。
返回值
类型: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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。