CloseDoc

<< Click to Display Table of Contents >>

Navigation:  Management >

CloseDoc

Previous pageReturn to chapter overviewNext page

Closes the specified document (and also the preview, if open).

method int VPE.CloseDoc( )

Returns:

Value

Description

True

Ok

False

couldn’t close, because the document is currently printed

Remarks:

You may call this method even if the document is already closed. In this case the method will return True.

 

Note: when a form which contains the VPE Control is being closed, it is very important that you call CloseDoc. You need to call CloseDoc exactly at the time when receiving the event which asks for confirmation if the form can be closed. (For C# and Visual Basic .NET it is the Form_Closing() event, for Visual Basic it is the Form_QueryUnload() event, for Delphi and C++ Builder it is the TForm.OnClose() event.)
In case CloseDoc should return False in that moment, you need to cancel the process of closing the window, i.e. the form must not be closed.

 

Example for Visual Basic .NET:

Private Sub MenuClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuClose.Click

 ' Do NOT call Application.Exit(), because Form1_Closing() will not be
 ' executed then!

 Close()

End Sub

 

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

 If Not Usage.CloseDoc Or Not Enhanced.CloseDoc Then

       MsgBox("The application cannot terminate until all jobs have finished printing.")

         e.Cancel = True

 End If

End Sub

 

Example for C#:

private void menuClose_Click(object sender, System.EventArgs e)

{

 // Do NOT call Application.Exit(), because Form1_Closing() will not be

 // executed then!

 Close();

}

 

private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)

{

 if (!Usage.CloseDoc() || !Enhanced.CloseDoc())

 {

       MessageBox.Show("The application cannot terminate until all jobs have finished printing.");

         e.Cancel = true;

 }

}

 

Example for Visual Basic:

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

 If Not VPE1.CloseDoc Or Not VPE2.CloseDoc Then

       MsgBox ("The application cannot terminate until all jobs have finished printing.")

         Cancel = True

 End If

End Sub

 

Example for Delphi:

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);

begin

 if not VPE1.CloseDoc or not VPE2.CloseDoc then

 begin

       ShowMessage('The application cannot terminate until all jobs have finished printing.');

         Action := caNone;

 end;

end;

 

In the above examples the form contains two VPE Controls named "VPE1" and "VPE2". For both controls it is checked whether their previews can be closed or not.