Partager via


Button.PrintObject Property

Definition

Gets or sets a value that indicates whether the Button is printed when the worksheet is printed.

public:
 property bool PrintObject { bool get(); void set(bool value); };
[System.ComponentModel.Browsable(false)]
public bool PrintObject { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.PrintObject : bool with get, set
Public Property PrintObject As Boolean

Property Value

true if the Button is printed when the worksheet is printed; otherwise, false.

Attributes

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 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);
}
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

Applies to