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
    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
        PnlPreview.Controls.Add(Ctrl)
        Me.BringToFront()
    End If
End Sub

Public Function GetPreview() As Control
    Try
        Select Case Extensie.ToLower
            Case ".doc", ".docx", ".rtf"
                Dim lic As New Aspose.Words.License
                lic.SetLicense("Aspose.Total.lic")
                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
                webpreview.Navigate(FileName)
                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.

Hi
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
            Return
        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
        previewDlg.ShowDialog()
    End Sub
End Class

Hope this helps.
Best regards,