在winforms项目中拼写检查richtextbox

问题描述

我有一个WinForms项目,其中包含用VB编写的RichTextBox(RTB)
我在实时出价工具中设置了ShortcutsEnabled = FALSE
要使用任何拼写检查器,我猜这需要设置为TRUE

那不是我的问题!我已经读了很多小时,超出了我的认可范围
如果您拥有ASP.Net或WPF项目,则应了解拼写检查很容易
好吧,我不是,这是NuGet的三位候选人没有这些候选人会提供很大帮助
WeCantSpell.Hunspell VPKSoft.SpellCheckUtility NetSpell

我不要求推荐
因为我找不到教程,对如何使用代码实现这些外接程序一无所知
以及不知道它们是否与WinForms兼容
我什至看了这个CP帖子
CP LINK

只是一个建议,如何使用这些插件之一或如何向实时出价代码添加拼写检查?

解决方法

要实现拼写检查,您可以尝试使用Nuget软件包NHunspell

首先,您需要从“ NuGet”中添加“ NHunspell”并将其导入。具体操作如下:

右键单击参考,然后选择“管理NuGet软件包...”,然后在搜索栏中键入“ NHunspell”并安装它:

enter image description here

第二步,您需要创建一个文件夹来存储“ .aff”和“ .dic”,就像这样。

enter image description here

下载包含相应文件的“ zip”,即可访问this site

这是您可以参考的演示。

Private Sub btCheck_Click(sender As Object,e As EventArgs) Handles btCheck.Click
    Dim affFile As String = AppDomain.CurrentDomain.BaseDirectory & "../../Dictionaries/en_us.aff"
    Dim dicFile As String = AppDomain.CurrentDomain.BaseDirectory & "../../Dictionaries/en_us.dic"
    lbSuggestion.Items.Clear()
    lbmorph.Items.Clear()
    lbStem.Items.Clear()

    Using hunspell As New Hunspell(affFile,dicFile)
        Dim correct As Boolean = hunspell.Spell(TextBox1.Text)
        checklabel.Text = TextBox1.Text + " is spelled " & (If(correct,"correct","not correct"))

        Dim suggestions As List(Of String) = hunspell.Suggest(TextBox1.Text)
        countlabel.Text = "There are " & suggestions.Count.ToString() & " suggestions"
        For Each suggestion As String In suggestions
            lbSuggestion.Items.Add("Suggestion is: " & suggestion)
        Next

        Dim morphs As List(Of String) = hunspell.Analyze(TextBox1.Text)
        For Each morph As String In morphs
            lbmorph.Items.Add("Morph is: " & morph)
        Next

        Dim stems As List(Of String) = hunspell.Stem(TextBox1.Text)
        For Each stem As String In stems
            lbStem.Items.Add("Word Stem is: " & stem)
        Next
    End Using
End Sub

结果

enter image description here

希望这可以为您提供帮助。