ControlExtensions.AddPropertyGrid 方法 (ControlCollection, Range, Single, Single, String)

按照指定的大小和位置向文档中添加一个新的 PropertyGrid 控件。

命名空间:  Microsoft.Office.Tools.Word
程序集:  Microsoft.Office.Tools.Word.v4.0.Utilities(在 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 中)

语法

声明
<ExtensionAttribute> _
Public Shared Function AddPropertyGrid ( _
    controls As ControlCollection, _
    range As Range, _
    width As Single, _
    height As Single, _
    name As String _
) As PropertyGrid
public static PropertyGrid AddPropertyGrid(
    this ControlCollection controls,
    Range range,
    float width,
    float height,
    string name
)

参数

  • width
    类型:System.Single
    控件的宽度(以磅为单位)。
  • height
    类型:System.Single
    控件的高度(以磅为单位)。

返回值

类型:Microsoft.Office.Tools.Word.Controls.PropertyGrid
添加到文档的控件。

使用说明

在 Visual Basic 和 C# 中,可以在 ControlCollection 类型的任何对象上将此方法作为实例方法来调用。当使用实例方法语法调用此方法时,请省略第一个参数。有关更多信息,请参见扩展方法 (Visual Basic)扩展方法(C# 编程指南)

异常

异常 条件
ArgumentNullException

name 或 range 参数为 nullnull 引用(在 Visual Basic 中为 Nothing),或者 name 参数长度为零。

ControlNameAlreadyExistsException

ControlCollection 实例中已存在一个同名控件。

InvalidRangeException

指定的范围无效。

备注

使用此方法可以将 PropertyGrid 对象添加到 ControlCollection 的末尾。

若要移除通过编程方式添加的 PropertyGrid,请使用 Remove 方法。

示例

下面的代码示例向第一个段落添加一个 PropertyGrid 控件,然后向第三个段落添加一个 Button 控件。然后在属性网格中显示该按钮的属性。若要使用此示例,请从文档级项目内的 ThisDocument 类中运行此示例。

Private Sub WordRangeAddPropertyGrid()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.InsertParagraphBefore()

    Dim PropertyGrid1 As Microsoft.Office.Tools.Word. _
        Controls.PropertyGrid = Me.Controls.AddPropertyGrid( _
        Me.Paragraphs(1).Range, 150, 150, "PropertyGrid1")

    Dim Button1 As Microsoft.Office.Tools.Word.Controls.Button _
        = Me.Controls.AddButton(Me.Paragraphs(3).Range, 56.25F, _
        17.25F, "Button1")
    Button1.Text = "OK"

    PropertyGrid1.SelectedObject = Button1
End Sub 
private void WordRangeAddPropertyGrid()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.InsertParagraphBefore();

    Microsoft.Office.Tools.Word.Controls.PropertyGrid
         propertyGrid1 = this.Controls.AddPropertyGrid(
         this.Paragraphs[1].Range, 150, 150, "propertyGrid1");

    Microsoft.Office.Tools.Word.Controls.Button button1 =
        this.Controls.AddButton(this.Paragraphs[3].Range,
        56.25F, 17.25F, "button1");
    button1.Text = "OK";

    propertyGrid1.SelectedObject = button1;
}

.NET Framework 安全性

请参见

参考

ControlExtensions 类

AddPropertyGrid 重载

Microsoft.Office.Tools.Word 命名空间