MS DocumentViewer
This commit is contained in:
@@ -66,6 +66,8 @@ Public Class DocumentViewer
|
||||
Private _TempFiles As New List(Of String)
|
||||
|
||||
Private Sub DocumentViewer_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||
' Ensure search is initialized once the control (and GdViewer) exists
|
||||
EnsureSearchInitialized()
|
||||
UpdateMainUi()
|
||||
End Sub
|
||||
'hallo
|
||||
@@ -110,7 +112,8 @@ Public Class DocumentViewer
|
||||
_licenseKey = pLicenseKey
|
||||
_licenseManager.RegisterKEY(_licenseKey)
|
||||
_Annotations = New Annotations(pLogConfig)
|
||||
_Search = New Search(pLogConfig, GdViewer)
|
||||
' Defer creating Search until GdViewer is ready
|
||||
EnsureSearchInitialized()
|
||||
_ToolbarSettings = pToolbarSettings
|
||||
|
||||
Dim oConfigPath = ConfigPath()
|
||||
@@ -122,6 +125,17 @@ Public Class DocumentViewer
|
||||
End Try
|
||||
End Function
|
||||
|
||||
' Create the Search helper only when both the log config and the GdViewer control exist
|
||||
Private Sub EnsureSearchInitialized()
|
||||
Try
|
||||
If _Search Is Nothing AndAlso _logConfig IsNot Nothing AndAlso GdViewer IsNot Nothing Then
|
||||
_Search = New Search(_logConfig, GdViewer)
|
||||
End If
|
||||
Catch ex As Exception
|
||||
_logger?.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Load a file from a path and display it
|
||||
''' </summary>
|
||||
@@ -223,7 +237,17 @@ Public Class DocumentViewer
|
||||
|
||||
Public Sub CloseDocument()
|
||||
Try
|
||||
GdViewer.CloseDocument()
|
||||
' Null-sicher schließen
|
||||
If GdViewer IsNot Nothing Then
|
||||
Try
|
||||
GdViewer.CloseDocument()
|
||||
Catch exInner As Exception
|
||||
_logger?.Warn("Fehler beim Schließen von GdViewer")
|
||||
_logger?.Error(exInner)
|
||||
End Try
|
||||
Else
|
||||
_logger?.Debug("CloseDocument: GdViewer ist Nothing – nichts zu schließen")
|
||||
End If
|
||||
|
||||
_FileInfo = Nothing
|
||||
_FilePath = Nothing
|
||||
@@ -299,23 +323,23 @@ Public Class DocumentViewer
|
||||
GdViewer.Focus()
|
||||
UpdateMainUi()
|
||||
End Sub
|
||||
Private Sub btnFirstPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonFirstPage.ItemClick
|
||||
Private Sub BtnFirstPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonFirstPage.ItemClick
|
||||
GdViewer.DisplayFirstPage()
|
||||
End Sub
|
||||
|
||||
Private Sub btnPreviousPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonPrevPage.ItemClick
|
||||
Private Sub BtnPreviousPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonPrevPage.ItemClick
|
||||
GdViewer.DisplayPreviousPage()
|
||||
End Sub
|
||||
|
||||
Private Sub btnNextPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonNextPage.ItemClick
|
||||
Private Sub BtnNextPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonNextPage.ItemClick
|
||||
GdViewer.DisplayNextPage()
|
||||
End Sub
|
||||
|
||||
Private Sub btnLastPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonLastPage.ItemClick
|
||||
Private Sub BtnLastPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonLastPage.ItemClick
|
||||
GdViewer.DisplayLastPage()
|
||||
End Sub
|
||||
|
||||
Private Sub tbCurrentPage_Leave(ByVal sender As System.Object, ByVal e As EventArgs) Handles txtCurrentPage.EditValueChanged
|
||||
Private Sub TbCurrentPage_Leave(ByVal sender As System.Object, ByVal e As EventArgs) Handles txtCurrentPage.EditValueChanged
|
||||
Dim page As Integer = 0
|
||||
If Integer.TryParse(txtCurrentPage.EditValue, page) Then
|
||||
If page > 0 And page <= GdViewer.PageCount Then
|
||||
@@ -352,11 +376,11 @@ Public Class DocumentViewer
|
||||
GdViewer.PrintDialog()
|
||||
End Sub
|
||||
|
||||
Private Sub btnRotateLeft_Click(sender As Object, e As EventArgs) Handles buttonRotateLeft.ItemClick
|
||||
Private Sub BtnRotateLeft_Click(sender As Object, e As EventArgs) Handles buttonRotateLeft.ItemClick
|
||||
GdViewer.Rotate(RotateFlipType.Rotate270FlipNone)
|
||||
End Sub
|
||||
|
||||
Private Sub btnRotateRight_Click(sender As Object, e As EventArgs) Handles buttonRotateRight.ItemClick
|
||||
Private Sub BtnRotateRight_Click(sender As Object, e As EventArgs) Handles buttonRotateRight.ItemClick
|
||||
GdViewer.Rotate(RotateFlipType.Rotate90FlipNone)
|
||||
End Sub
|
||||
|
||||
@@ -381,7 +405,7 @@ Public Class DocumentViewer
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub btnSettings_Click(ByVal sender As Object, ByVal e As EventArgs) Handles buttonSettings.ItemClick
|
||||
Private Sub BtnSettings_Click(ByVal sender As Object, ByVal e As EventArgs) Handles buttonSettings.ItemClick
|
||||
Using frmSettings As New frmViewerSettings(GdViewer)
|
||||
frmSettings.ShowDialog(Me)
|
||||
End Using
|
||||
@@ -468,6 +492,12 @@ Public Class DocumentViewer
|
||||
End Sub
|
||||
Private Function DoLoadFile(FilePath As String, Optional ViewOverride As String = "") As Boolean
|
||||
Try
|
||||
' Ensure the embedded GdViewer control exists before using it
|
||||
If Not EnsureViewerReady() Then
|
||||
_logger?.Warn("GdViewer control is not initialized yet. Delaying load.")
|
||||
Return False
|
||||
End If
|
||||
|
||||
lblInfo.Visible = False
|
||||
Dim oFileInfo = New FileInfo(FilePath)
|
||||
Dim oExtension As String = oFileInfo.Extension.ToUpper
|
||||
@@ -503,12 +533,6 @@ Public Class DocumentViewer
|
||||
GdViewer.Visible = False
|
||||
SpreadsheetControl1.Dock = DockStyle.Fill
|
||||
|
||||
'Case ".EML", ".DOC", ".DOCX", ".ODT", ".RTF", ".TXT"
|
||||
' RichEditControl1.LoadDocument(FilePath, GetDocumentFormat(oExtension))
|
||||
|
||||
' RichEditControl1.Visible = True
|
||||
' GdViewer.Visible = False
|
||||
' RichEditControl1.Dock = DockStyle.Fill
|
||||
Case Else
|
||||
Select Case oExtension.ToUpper
|
||||
Case ".EML", ".DOC", ".DOCX", ".XLS", ".XLSX", ".ODT", ".RTF", ".TXT"
|
||||
@@ -555,6 +579,32 @@ Public Class DocumentViewer
|
||||
End Try
|
||||
End Function
|
||||
|
||||
' Ensures the embedded GdViewer control exists and is added to the visual tree
|
||||
Private Function EnsureViewerReady() As Boolean
|
||||
Try
|
||||
' If the control field is Nothing (e.g., designer not yet created), try to lazy-create and add it
|
||||
If GdViewer Is Nothing Then
|
||||
' Attempt to find an existing instance by name in Controls collection
|
||||
Dim existing = Me.Controls.OfType(Of GdPicture14.GdViewer)().FirstOrDefault()
|
||||
If existing IsNot Nothing Then
|
||||
' Assign the designer field via reflection if needed, otherwise use it directly
|
||||
GdViewer = existing
|
||||
Else
|
||||
' Last resort: create a new viewer and add it
|
||||
Dim viewer = New GdPicture14.GdViewer()
|
||||
viewer.Dock = DockStyle.Fill
|
||||
Me.Controls.Add(viewer)
|
||||
GdViewer = viewer
|
||||
End If
|
||||
End If
|
||||
|
||||
Return GdViewer IsNot Nothing
|
||||
Catch ex As Exception
|
||||
_logger?.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Sub FitToPage()
|
||||
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeFitToViewer
|
||||
End Sub
|
||||
@@ -703,18 +753,21 @@ Public Class DocumentViewer
|
||||
End Sub
|
||||
|
||||
Private Sub btnSearch2_ItemClick(sender As Object, e As XtraBars.ItemClickEventArgs) Handles btnSearch2.ItemClick
|
||||
If Not String.IsNullOrEmpty(txtSearch.EditValue) Then
|
||||
EnsureSearchInitialized()
|
||||
If _Search IsNot Nothing AndAlso Not String.IsNullOrEmpty(txtSearch.EditValue) Then
|
||||
_Search.SearchAll(txtSearch.EditValue?.ToString)
|
||||
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub btnPrevHighlight_ItemClick(sender As Object, e As XtraBars.ItemClickEventArgs) Handles btnPrevHighlight.ItemClick
|
||||
_Search.PrevHighlight()
|
||||
EnsureSearchInitialized()
|
||||
_Search?.PrevHighlight()
|
||||
End Sub
|
||||
|
||||
Private Sub btnNextHighlight_ItemClick(sender As Object, e As XtraBars.ItemClickEventArgs) Handles btnNextHighlight.ItemClick
|
||||
_Search.NextHighlight()
|
||||
EnsureSearchInitialized()
|
||||
_Search?.NextHighlight()
|
||||
End Sub
|
||||
|
||||
Private Sub txtSearch_EditValueChanged(sender As Object, e As EventArgs) Handles txtSearch.EditValueChanged
|
||||
|
||||
Reference in New Issue
Block a user