We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Application looses focus

We have a problem in .net that our application sometimes looses the focus with the folowing code:

following sub is in the form

Private Sub bsBijlages_CurrentChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles bsBijlages.CurrentChanged<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

PnlPreview.Controls.Clear() 'Panel that hosts the preview controls

If bsBijlages.Current IsNot Nothing Then

'Get the preview as a control. Can be Webbrowser control or printpreviewcontrol

Dim Ctrl As Control = DirectCast(bsBijlages.Current, DossierBijlageInfo).GetPreview

Ctrl.Dock = DockStyle.Fill



End If

End Sub

Public Function GetPreview() As Control


Select Case Extensie.ToLower

Case ".doc", ".docx", ".rtf"

Dim lic As New Aspose.Words.License


Dim FileName As String = GetFileName()

If String.IsNullOrEmpty(FileName) Then Throw New Exception("Invalid filename")

Dim doc As New Document(FileName)

Dim previewDlg As New PrintPreviewControl

Dim awPrintDoc As New AsposeWordsPrintDocument(doc)

previewDlg.Document = awPrintDoc

previewDlg.Zoom = 1

Return previewDlg

Case ".pdf", ".jpg", ".gif", ".png", ".tiff", ".htm", ".html"

Dim FileName As String = GetFileName()

If String.IsNullOrEmpty(FileName) Then Throw New Exception

Dim webpreview As New WebBrowser


Return webpreview

Case Else

Dim webpreview As New WebBrowser

webpreview.DocumentText = "Er is geen preview beschikbaar" 'No preview available

Return webpreview

End Select

Catch ex As Exception

Dim webpreview As New WebBrowser

webpreview.DocumentText = "De preview kan niet worden getoond" 'unable to show the preview

Return webpreview

End Try

End Function

Problem is when we want to show a preview of a word document most of the time our program looses the focus en is putted behind all the open windows programs.


Thanks for your request. But I am not sure that the issue is actually related to Aspose.Words. However, you can try using the same code as used in our demos to show PrintPreview dialog (See DocumentExplorer demo):


''' Provides a utility method to print preview and print an Aspose.Words document.


Friend Class Preview


''' No ctor.


Private Sub New()

End Sub


''' A utility method to print preview and print an Aspose.Words document.


Friend Shared Sub Execute(ByVal document As Document)

' This operation can take some time (for the first page) so we set the Cursor to WaitCursor.

Dim cursor As Cursor = Cursor.Current

Cursor.Current = Cursors.WaitCursor

Dim previewDlg As New PrintPreviewDialog()

' Initialize the Print Dialog with the number of pages in the document.

Dim printDlg As New PrintDialog()

printDlg.AllowSomePages = True

printDlg.PrinterSettings = New PrinterSettings()

printDlg.PrinterSettings.MinimumPage = 1

printDlg.PrinterSettings.MaximumPage = document.PageCount

printDlg.PrinterSettings.FromPage = 1

printDlg.PrinterSettings.ToPage = document.PageCount

' Restore cursor.

Cursor.Current = cursor

' Interesting, but PrintDialog will not show and will always return cancel

' if you run this application in 64-bit mode.

If (Not printDlg.ShowDialog().Equals(DialogResult.OK)) Then


End If

' Create the Aspose.Words' implementation of the .NET print document

' and pass the printer settings from the dialog to the print document.

Dim awPrintDoc As New AsposeWordsPrintDocument(document)

awPrintDoc.PrinterSettings = printDlg.PrinterSettings

' Pass the Aspose.Words' print document to the .NET Print Preview dialog.

previewDlg.Document = awPrintDoc


End Sub

End Class

Hope this helps.

Best regards,