DocumentBase.BeforePrint 事件

定义

在打印文档之前发生。

public event System.ComponentModel.CancelEventHandler BeforePrint;

事件类型

CancelEventHandler

示例

下面的代码示例在打印文档之前显示一条消息,询问您是否要打印文档。 若要使用此示例,请在 ThisDocument 文档级项目的类中运行它。

private void DocumentBeforePrint()
{
    this.BeforePrint += new System.ComponentModel.CancelEventHandler(ThisDocument_BeforePrint);
}

void ThisDocument_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e)
{
    if (MessageBox.Show("Do you want to print the document?", "BeforePrint",
        MessageBoxButtons.YesNo) == DialogResult.No)
    {
        e.Cancel = true;
    }
}
Private Sub DocumentBeforePrint()
    AddHandler Me.BeforePrint, AddressOf ThisDocument_BeforePrint
End Sub

Private Sub ThisDocument_BeforePrint(ByVal sender As Object, ByVal e As System. _
    ComponentModel.CancelEventArgs)
    If MessageBox.Show("Do you want to print the document?", "BeforePrint", _
        MessageBoxButtons.YesNo) = DialogResult.No Then
        e.Cancel = True
    End If
End Sub

注解

若要防止打印文档,请将 Cancel 提供的对象的参数设置 CancelEventArgstrue

适用于