Button.Application 属性
获取一个 Application 对象,该对象表示 Button 的创建者。
命名空间: Microsoft.Office.Tools.Excel.Controls
程序集: Microsoft.Office.Tools.Excel.v4.0.Utilities(在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)
语法
声明
Public ReadOnly Property Application As Application
public Application Application { get; }
属性值
类型:Microsoft.Office.Interop.Excel.Application
一个 Application 对象,表示该 Button 的创建者。
示例
下面的代码示例向当前工作表中添加一个 Button 控件。 该按钮的 Click 事件处理程序显示 Creator 和 Application 属性的值。
此示例针对的是文档级自定义项。
Private Sub DisplayCreatorAndApplication()
Dim CreatorButton1 As Microsoft.Office.Tools.Excel.Controls.Button = _
Me.Controls.AddButton(Me.Range("B2", "C3"), "CreatorButton1")
CreatorButton1.Text = "Click to view creator and application"
AddHandler CreatorButton1.Click, AddressOf CreatorButton_Click
End Sub
Private Sub CreatorButton_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)
Dim ApplicationString As String = "The current application is " & _
ClickedButton.Application.Name.ToString()
If ClickedButton.Creator = Excel.XlCreator.xlCreatorCode Then
MsgBox(ApplicationString & ". Created by Microsoft Excel")
Else
MsgBox(ApplicationString & _
". Created by an application other than Microsfot Excel")
End If
End Sub
private void DisplayCreatorAndApplication()
{
Microsoft.Office.Tools.Excel.Controls.Button creatorButton1 =
this.Controls.AddButton(this.Range["B2", "C3"],
"creatorButton1");
creatorButton1.Text = "Click to view creator and application";
creatorButton1.Click += new EventHandler(creatorButton_Click);
}
void creatorButton_Click(object sender, EventArgs e)
{
Microsoft.Office.Tools.Excel.Controls.Button clickedButton =
(Microsoft.Office.Tools.Excel.Controls.Button)sender;
string applicationString = "The current application is " +
clickedButton.Application.Name.ToString();
if (clickedButton.Creator == Excel.XlCreator.xlCreatorCode)
{
MessageBox.Show(applicationString +
". Created by Microsoft Excel");
}
else
{
MessageBox.Show(applicationString +
". Created by an application other than Microsfot Excel");
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。