DevExpress控件使用交流,DevExpress中国社区Dev联系电话 联系电话:023-68661681

DevExpress WinForms在线示例:XtraSpellChecker入门指南(一)

来源:   发布时间:2018-03-20   浏览:3032次

本主题将展示如何使用SpellChecker组件向应用程序添加拼写检查功能。美国英语词典是内置的,默认情况下将使用。

SpellChecker组件可以检查各种文本编辑器的拼写。

请按照以下步骤操作。我们假设应用程序的表单具有来自所支持的控件列表中的几个不同的文本编辑器。

  • 步骤1.添加拼写检查器组件
  • 步骤2.按需检查拼写
  • 步骤3.键入时检查拼写

步骤1.添加拼写检查器组件

将SpellChecker组件添加到项目中。为此,只需从DX.18.2:Components工具箱选项卡中拖动相应的项,并将其拖放到包含文本控件的表单上。

DevExpress

步骤2.按需添加拼写检查代码

在单击按钮时,开始检查表单上所有支持的控件中的拼写:

  • 将SimpleButton控件(位于DX.18.2:Common Controls工具箱选项卡上)添加到表单;
  • 订阅按钮的Click事件。
  • 要开始拼写检查并在单击按钮时调用拼写对话框进行更正,请调用SpellChecker.CheckContainer方法。
    private void simpleButton1_Click(object sender, EventArgs e)
    {
        spellChecker1.CheckContainer(this);
    }
    Private Sub simpleButton1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles simpleButton1.Click
        spellChecker1.CheckContainer(Me)
    End Sub

步骤3.在键入时添加拼写检查代码

要使SpellChecker能够在键入时检查表单上所有支持的控件的拼写:

  • 订阅表单的加载事件;
  • 向Load事件处理程序添加以下代码:
    private void Form1_Load(object sender, EventArgs e)
    {
        // Set spell checking options.
        spellChecker1.SpellCheckMode = DevExpress.XtraSpellChecker.SpellCheckMode.AsYouType;
        spellChecker1.ParentContainer = this;
        spellChecker1.CheckAsYouTypeOptions.CheckControlsInParentContainer = true;
        // Set focus to the RichTextBox control to show red wavy lines under misspelled words.
        richTextBox1.Select();
    }
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        ' Set spell checking options.
        spellChecker1.SpellCheckMode = DevExpress.XtraSpellChecker.SpellCheckMode.AsYouType
        spellChecker1.ParentContainer = Me
        spellChecker1.CheckAsYouTypeOptions.CheckControlsInParentContainer = True
        ' Set focus to the RichTextBox control to show red wavy lines under misspelled words.
        richTextBox1.Select()
    End Sub

    这段代码指示SpellChecker在最终用户输入完单词或更改后移动光标时对拼写错误的单词下划线,并允许从上下文菜单中选择建议,通过右击单词来调用。

步骤4.运行项目

拼错的单词在具有焦点的文本控件中是下划线。RichEditControl始终显示下划线是否具有焦点,如下图所示:

DevExpress

单击Check Spelling按钮开始检查表单上所有控件的拼写并调用拼写对话框。

买 DevExpress Universal Subscription  免费赠 万元汉化资源包1套!

限量15套!先到先得,送完即止!立即抢购>>

本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/1113.html

相关产品: DevExpress Universal Subscription,

在线
客服
微信
QQ 电话
023-68661681
返回
顶部