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.