ControlCollection.AddLabel 方法 (Double, Double, Double, Double, String) (2007 system)

更新:2007 年 11 月

按照指定的大小和位置向工作表添加一个新的 Label 控件。

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel.v9.0(在 Microsoft.Office.Tools.Excel.v9.0.dll 中)

语法

声明
Public Function AddLabel ( _
    left As Double, _
    top As Double, _
    width As Double, _
    height As Double, _
    name As String _
) As Label
用法
Dim instance As ControlCollection
Dim left As Double
Dim top As Double
Dim width As Double
Dim height As Double
Dim name As String
Dim returnValue As Label

returnValue = instance.AddLabel(left, _
    top, width, height, name)
public Label AddLabel(
    double left,
    double top,
    double width,
    double height,
    string name
)

参数

  • left
    类型:System.Double

    控件左边缘与工作表左边缘之间的距离(以磅为单位)。

  • top
    类型:System.Double

    控件上边缘与工作表上边缘之间的距离(以磅为单位)。

  • width
    类型:System.Double

    控件的宽度(以磅为单位)。

  • height
    类型:System.Double

    控件的高度(以磅为单位)。

返回值

类型:Microsoft.Office.Tools.Excel.Controls.Label

添加到 ControlCollection 实例的 Label 控件。

异常

异常 条件
ArgumentNullException

名称参数为 nullnull 引用(在 Visual Basic 中为 Nothing) 或长度为零。

ControlNameAlreadyExistsException

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

备注

使用 AddLabel 方法可以将 Label 对象添加到 ControlCollection 的末尾。若要移除以前以编程方式添加的 Label 控件,请使用 Remove() 方法。

示例

下面的代码示例将一个 Label 控件添加到工作表顶端,然后将控件文本更改为 First Name。

Private Sub ExcelAddLabel()

    Dim Label1 As Microsoft.Office.Tools.Excel. _
        Controls.Label = Me.Controls.AddLabel( _
        0, 0, 75, 17.25, "Label1")
    Label1.Text = "First Name"

End Sub

private void ExcelAddLabel()
{

    Microsoft.Office.Tools.Excel.Controls.Label
        label1 = this.Controls.AddLabel(
        0, 0, 75, 17.25, "label1");
    label1.Text = "First Name";
}

权限

另请参见

参考

ControlCollection 类

ControlCollection 成员

AddLabel 重载

Microsoft.Office.Tools.Excel 命名空间