Files
staxrip/Forms/HelpForm.vb
T
2015-11-22 22:13:49 +01:00

152 lines
4.6 KiB
VB.net

Imports StaxRip.UI
Public Class HelpForm
Inherits FormBase
#Region " Designer "
<System.Diagnostics.DebuggerNonUserCode()>
Protected Overloads Overrides Sub Dispose(disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
Friend WithEvents Browser As System.Windows.Forms.WebBrowser
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Me.Browser = New System.Windows.Forms.WebBrowser()
Me.SuspendLayout()
'
'Browser
'
Me.Browser.Dock = System.Windows.Forms.DockStyle.Fill
Me.Browser.Location = New System.Drawing.Point(0, 0)
Me.Browser.Name = "Browser"
Me.Browser.Size = New System.Drawing.Size(960, 651)
Me.Browser.TabIndex = 0
'
'HelpForm
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(144.0!, 144.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None
Me.ClientSize = New System.Drawing.Size(960, 651)
Me.Controls.Add(Me.Browser)
Me.Font = New System.Drawing.Font("Segoe UI", 9.0!)
Me.KeyPreview = True
Me.Name = "HelpForm"
Me.ResumeLayout(False)
End Sub
#End Region
Sub New()
InitializeComponent()
Icon = My.Resources.MainIcon
End Sub
Sub New(path As String)
Me.New()
Try
Browser.Navigate(path)
Catch ex As Exception
MsgWarn("Failed to load: " + path)
End Try
Icon = My.Resources.MainIcon
End Sub
Private DocumentValue As HelpDocument
Property Doc() As HelpDocument
Get
If DocumentValue Is Nothing Then
Dim path = CommonDirs.Temp + Guid.NewGuid.ToString + ".htm"
AddHandler g.MainForm.Disposed, Sub() FileHelp.Delete(path)
DocumentValue = New HelpDocument(path)
End If
Return DocumentValue
End Get
Set(Value As HelpDocument)
DocumentValue = Value
End Set
End Property
Overloads Shared Sub ShowDialog(heading As String, tips As StringPairList)
ShowDialog(heading, tips, Nothing)
End Sub
Overloads Shared Sub ShowDialog(heading As String, tips As StringPairList, summary As String)
Dim f As New HelpForm()
f.Doc.WriteStart(heading)
If Not summary Is Nothing Then
f.Doc.WriteP(summary)
End If
f.Doc.WriteTips(tips)
f.Show()
End Sub
Private Sub HelpForm_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
Dispose()
End Sub
Private Sub Browser_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles Browser.DocumentCompleted
WebBrowserHelp.ResetTextSize(Browser)
End Sub
Private Sub Browser_Navigated(sender As Object, e As WebBrowserNavigatedEventArgs) Handles Browser.Navigated
If Browser.DocumentTitle <> "" Then
Text = Browser.DocumentTitle
ElseIf File.Exists(e.Url.LocalPath) Then
Text = Filepath.GetBase(e.Url.LocalPath)
End If
End Sub
Shadows Sub Show()
MyBase.Show()
Application.DoEvents()
If Not DocumentValue Is Nothing Then
DocumentValue.WriteDocument(Browser)
End If
End Sub
Private Sub Browser_Navigating(sender As Object, e As WebBrowserNavigatingEventArgs) Handles Browser.Navigating
If e.Url.AbsoluteUri.StartsWith("http://") Then
e.Cancel = True
g.ShellExecute(e.Url.ToString)
End If
End Sub
Shared ReadOnly Property MainImagePath() As String
Get
Dim filepath = CommonDirs.Temp + Guid.NewGuid.ToString + ".gif"
If Not File.Exists(filepath) Then
AddHandler g.MainForm.Disposed, Sub() FileHelp.Delete(filepath)
File.WriteAllBytes(filepath, My.Resources.main_gif)
End If
Return filepath
End Get
End Property
Shared ReadOnly Property BackgroundImagePath() As String
Get
Dim filepath = CommonDirs.Temp + Guid.NewGuid.ToString + ".gif"
If Not File.Exists(filepath) Then
AddHandler g.MainForm.Disposed, Sub() FileHelp.Delete(filepath)
File.WriteAllBytes(filepath, My.Resources.background_gif)
End If
Return filepath
End Get
End Property
End Class