Completed
Last Updated: 02 Apr 2015 09:49 by ADMIN
ADMIN
Dess | Tech Support Engineer, Sr.
Created on: 24 Mar 2015 12:11
Category: Editors
Type: Bug Report
0
FIX. RadTextBoxControl - right clicking a correct word should not display spell-checking popup with suggestions
Please refer to the attached gif file.

Workaround:

public Form1()
{
    InitializeComponent();

    this.radSpellChecker1.AutoSpellCheckControl = this.radTextBoxControl1;
    this.radTextBoxControl1.Multiline = true;
    this.radTextBoxControl1.ContextMenuOpening += radTextBoxControl1_ContextMenuOpening;
}

public static bool containsError = false;
public static bool isMisspelledWord = true;

private void radTextBoxControl1_ContextMenuOpening(object sender, TreeBoxContextMenuOpeningEventArgs e)
{
    if (!isMisspelledWord && containsError)
    {
        //do not show the context when you click over a correct word
        e.Cancel = true;
    }
}

public class MyTextBox : RadTextBoxControl
{
    protected override RadTextBoxControlElement CreateTextBoxElement()
    {
        return new MyTextBoxElement();
    }

    public override string ThemeClassName
    {
        get
        {
            return typeof(RadTextBoxControl).FullName;
        }
    }
}

public class MyTextBoxElement : RadTextBoxControlElement
{
    RadSpellChecker sp = new RadSpellChecker();

    protected override void OnMouseDown(MouseEventArgs e)
    {
        sp.AutoSpellCheckControl = this.ElementTree.Control;
        containsError = false;
        isMisspelledWord = true;
        if (e.Button == System.Windows.Forms.MouseButtons.Right)
        {
            Point location = this.ElementTree.Control.PointToClient(Cursor.Position);
            TextPosition position = this.Navigator.GetPositionFromPoint(location);
            this.Navigator.CaretPosition = position;

            if (this.Multiline)
            {
                this.Navigator.ScrollToCaret();
            }
            ITextBoxNavigator navigator = this.Navigator;

            TextPosition caretPosition = navigator.CaretPosition;
            LineInfo line = caretPosition.Line;
            ITextBlock textBlock = caretPosition.TextBlock;
            string clickedWordInRadTextBox = textBlock.Text;
            if (string.IsNullOrEmpty(clickedWordInRadTextBox) || clickedWordInRadTextBox == " ")
            {
                return;
            }
            TextBoxSpellChecker tbSpellChecker = sp.GetControlSpellChecker(typeof(RadTextBoxControl)) as TextBoxSpellChecker;
            ICollection<string> suggestions = tbSpellChecker.SpellChecker.GetSuggestions(clickedWordInRadTextBox);

            if (suggestions.Count > 0)
            {
                containsError = true;
            }

            if (tbSpellChecker.SpellChecker.CheckWordIsCorrect(clickedWordInRadTextBox))
            {
                isMisspelledWord = false;
            }
            base.OnMouseDown(e);
        }
    }

    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(RadTextBoxControlElement);
        }
    }
}
Attached Files:
0 comments