Button.PrintObject 属性
获取或设置一个值,该值指示打印工作表时,是否打印 Button。
命名空间: Microsoft.Office.Tools.Excel.Controls
程序集: Microsoft.Office.Tools.Excel.v4.0.Utilities(在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)
语法
声明
<BrowsableAttribute(False)> _
Public Property PrintObject As Boolean
Get
Set
[BrowsableAttribute(false)]
public bool PrintObject { get; set; }
属性值
类型:System.Boolean
如果在打印工作表时打印 Button,则为 true;否则为 false。
示例
下面的代码示例演示了一个带有 Click 事件处理程序的 Button 控件,该事件处理程序生成工作表的打印预览。 该事件处理程序提示用户指定是否通过设置 PrintObject 属性在打印预览中显示该按钮。
此示例针对的是文档级自定义项。
Private Sub PrintControl()
Dim PrintButton As Microsoft.Office.Tools.Excel.Controls.Button = _
Me.Controls.AddButton(Me.Range("C2", "D3"), "PrintButton")
PrintButton.Text = "Print preview"
AddHandler PrintButton.Click, AddressOf printButton_Click
' Set a range value so that a print preview is generated even
' if the button is hidden from the preview.
Me.Range("A1", "A10").Value2 = 123
End Sub
Private Sub PrintButton_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)
' Allow the user to hide the button from print previews.
If DialogResult.No = MessageBox.Show( _
"Include the button when printing the sheet?", "Example", _
MessageBoxButtons.YesNo) Then
ClickedButton.PrintObject = False
End If
Me.PrintPreview(True)
End Sub
private void PrintControl()
{
Microsoft.Office.Tools.Excel.Controls.Button printButton =
this.Controls.AddButton(this.Range["C2", "D3"],
"printButton");
printButton.Text = "Print preview";
printButton.Click += new EventHandler(printButton_Click);
// Set a range value so that a print preview is generated even
// if the button is hidden from the preview.
this.Range["A1", "A10"].Value2 = 123;
}
void printButton_Click(object sender, EventArgs e)
{
Microsoft.Office.Tools.Excel.Controls.Button clickedButton =
(Microsoft.Office.Tools.Excel.Controls.Button)sender;
if (DialogResult.No ==
MessageBox.Show("Include the button when printing the sheet?",
"Example", MessageBoxButtons.YesNo))
{
clickedButton.PrintObject = false;
}
this.PrintPreview(true);
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。