Поделиться через


Document.BeforePrint Событие (2007 System)

Обновлен: Июль 2008

Это происходит перед выводом документа на печать.

Пространство имен:  Microsoft.Office.Tools.Word
Сборка:  Microsoft.Office.Tools.Word.v9.0 (в Microsoft.Office.Tools.Word.v9.0.dll)

Синтаксис

'Декларация
Public Event BeforePrint As CancelEventHandler
'Применение
Dim instance As Document
Dim handler As CancelEventHandler

AddHandler instance.BeforePrint, handler
public event CancelEventHandler BeforePrint

Заметки

Чтобы предотвратить вывод документа на печать, присвойте аргументу Cancel предоставленного объекта CancelEventArgs значение 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
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()
    Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
    AddHandler vstoDoc.BeforePrint, AddressOf ThisDocument_BeforePrint
End Sub

Private Sub ThisDocument_BeforePrint(ByVal sender As Object, ByVal e As System. _
    ComponentModel.CancelEventArgs)
    Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
    If System.Windows.Forms.MessageBox.Show("Do you want to print the document?", "BeforePrint", _
        System.Windows.Forms.MessageBoxButtons.YesNo) = System.Windows.Forms.DialogResult.No Then
        e.Cancel = True
    End If
End Sub
private void DocumentBeforePrint()
{
    Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
    vstoDoc.BeforePrint += new System.ComponentModel.CancelEventHandler(ThisDocument_BeforePrint);
}

void ThisDocument_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e)
{
    if (System.Windows.Forms.MessageBox.Show("Do you want to print the document?", "BeforePrint",
        System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
    {
        e.Cancel = true;
    }
}

Разрешения

См. также

Ссылки

Document Класс

Document - члены

Microsoft.Office.Tools.Word - пространство имен

Журнал изменений

Дата

Журнал событий

Причина

Июль 2008

Добавлена версия кода для надстройки уровня приложения.

Изменение функции SP1.