Imports SolidEdgeFileProperties
Imports System.Runtime.InteropServices


Public Class DraftSpellChecker

    Private Sub DraftSpellChecker_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'identify misspelled word
        Me.RTxtMispelled.AppendText(strTextStringToBeChecked)
        Me.RTxtMispelled.SelectionStart = Me.RTxtMispelled.Find(strParsedString)
        Me.RTxtMispelled.SelectionColor = System.Drawing.Color.Red

        ' add suggested spellings
        For Each w In suggestions
            Me.ListBox1.Items.Add(w)
        Next

        objSEApp.StatusBar = "Please correct spelling. "

    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        EndProg()

    End Sub


    Private Sub btnIgnore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIgnore.Click
        strTextStringCorrected = ""
        Me.RTxtMispelled.Clear()
        Me.ListBox1.Items.Clear()
        suggestions.Clear()
        Me.Hide()

        objSEApp.StatusBar = " "

    End Sub

    Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click

        strTextStringCorrected = Me.ListBox1.SelectedItem
        If strTextStringCorrected = "" Then
            MsgBox("Replacement word not selected.  Please select the replacement word.")
            Exit Sub
        End If

        Me.RTxtMispelled.Clear()
        Me.ListBox1.Items.Clear()
        suggestions.Clear()
        Me.Hide()
    End Sub

    Private Sub BtnClose(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        EndProg()

    End Sub

    Private Sub EndProg()
        '******* Added because of .NET
        Try
            MessageFilter.Revoke()

            objSEApp.StatusBar = " "

        Catch ex As Exception
            MsgBox("Error revoking message filter.", MsgBoxStyle.OkOnly)
        End Try
        '******* Added because of .NET

        Me.Hide()
        Me.Dispose()


        If Not (SpellCheckForm Is Nothing) Then
            SpellCheckForm.Dispose()
            SpellCheckForm = Nothing
        End If

        If Not (MSWord Is Nothing) Then
            MSWord.Quit()
            Marshal.ReleaseComObject(MSWord)
            MSWord = Nothing
        End If

        If Not (objSheets Is Nothing) Then
            Marshal.ReleaseComObject(objSheets)
            objSheets = Nothing
        End If

        If Not (objSEApp Is Nothing) Then
            Marshal.ReleaseComObject(objSEApp)
            objSEApp = Nothing
        End If

        If Not (objDraftDoc Is Nothing) Then
            Marshal.ReleaseComObject(objDraftDoc)
            objDraftDoc = Nothing
        End If

        Garbage_Collect(MSWord)
        Garbage_Collect(objSheets)
        Garbage_Collect(objDraftDoc)
        Garbage_Collect(objSEApp)

        End

    End Sub
End Class
