Button.PrintObject Property
Gets or sets a value that indicates whether the Button is printed when the worksheet is printed.
Namespace: Microsoft.Office.Tools.Excel.Controls
Assembly: Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)
Syntax
'Declaration
<BrowsableAttribute(False)> _
Public Property PrintObject As Boolean
[BrowsableAttribute(false)]
public bool PrintObject { get; set; }
Property Value
Type: System.Boolean
true if the Button is printed when the worksheet is printed; otherwise, false.
Examples
The following code example demonstrates a Button control with a Click event handler that generates a print preview of the worksheet. The event handler prompts the user to specify whether the button should appear in the print preview by setting the PrintObject property.
This example is for a document-level customization.
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 Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.