Button.Parent 属性

获取 Button 的父对象。

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

语法

声明
Public ReadOnly Property Parent As Object
    Get
public Object Parent { get; }

属性值

类型:System.Object
Button 的父对象。

备注

Button 的父对象是一个连接 Button 和文档的容器控件,而不是包含 ButtonRange

Button 的父对象仅可作为 Object 进行访问。

示例

下面的代码示例向当前工作表中添加一个 Button 控件。 该按钮的 Click 事件处理程序显示 Parent 属性的值。

此示例针对的是文档级自定义项。

Private Sub DisplayParent()
    Dim ParentButton As Microsoft.Office.Tools.Excel.Controls.Button = _
        Me.Controls.AddButton(Me.Range("B2", "C3"), "ParentButton")
    ParentButton.Text = "Click to view parent"
    AddHandler ParentButton.Click, AddressOf parentButton_Click
End Sub

Private Sub ParentButton_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim ClickedButton As Microsoft.Office.Tools.Excel.Controls.Button = _
        CType(sender, Microsoft.Office.Tools.Excel.Controls.Button)

    MsgBox("The parent is: " & ClickedButton.Parent.ToString())
End Sub
private void DisplayParent()
{
    Microsoft.Office.Tools.Excel.Controls.Button parentButton =
            this.Controls.AddButton(this.Range["B2", "C3"],
            "parentButton");
    parentButton.Text = "Click to view parent";
    parentButton.Click += new EventHandler(parentButton_Click);
}

void parentButton_Click(object sender, EventArgs e)
{
    Microsoft.Office.Tools.Excel.Controls.Button clickedButton =
        (Microsoft.Office.Tools.Excel.Controls.Button)sender;

    MessageBox.Show("The parent is: " +
        clickedButton.Parent.ToString());
}

.NET Framework 安全性

请参见

参考

Button 类

Microsoft.Office.Tools.Excel.Controls 命名空间