共用方式為


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
[BrowsableAttribute(false)]
public bool PrintObject { get; set; }

屬性值

型別:System.Boolean
如果在列印工作表時會列印 Button,則為 true,否則為 false。

範例

下列程式碼範例會示範 Button 控制項以及會產生工作表預覽列印的 Click 事件處理常式。事件處理常式會提示使用者設定 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 安全性

請參閱

參考

Button 類別

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