Completed
Last Updated: 05 Nov 2015 12:21 by ADMIN
ADMIN
Dess | Tech Support Engineer, Sr.
Created on: 22 Oct 2015 14:44
Category: Editors
Type: Bug Report
0
FIX. RadTextBox - default context menu is not shown when the control is spellchecked and no misspelled words are available
To reproduce:

 RadSpellChecker radSpellChecker1 = new RadSpellChecker(); 

        public Form1()
        { 
            InitializeComponent(); 
           
            RadTextBox radTextBox1 = new RadTextBox();
            radTextBox1.Location = new Point(10, 10);
            this.Controls.Add(radTextBox1); 
             this.radSpellChecker1.AutoSpellCheckControl = radTextBox1; 

        }

1. Enter some valid text.
2. Select the content and right click with the mouse in order to copy the text by using the default context menu. However, the menu does not show.

Note: if the control is not spellchecked, it shows default context menu associated with MS TextBox.

Workaround: display your own menu with copy/paste options when no misspelled words are available.

RadContextMenu menu = new RadContextMenu();

public TestSpellchecker()
{
    InitializeComponent();

    RadMenuItem copyItem = new RadMenuItem("Copy");
    copyItem.Click += copyItem_Click;
    menu.Items.Add(copyItem);

    RadMenuItem pasteItem = new RadMenuItem("Paste");
    pasteItem.Click += pasteItem_Click;
    menu.Items.Add(pasteItem);

    this.radTextBox1.TextBoxElement.TextBoxItem.TextBoxControl.MouseDown += TextBoxControl_MouseDown;
}

private void pasteItem_Click(object sender, EventArgs e)
{
    this.radTextBox1.Paste();
}

private void copyItem_Click(object sender, EventArgs e)
{
    this.radTextBox1.Copy();
}

static Regex wordParser = new Regex(@"[\p{L}\p{N}\p{M}]+(?:[-.'´_@][\p{L}|\p{N}|\p{M}]+)*", RegexOptions.Compiled);

private void TextBoxControl_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == System.Windows.Forms.MouseButtons.Right)
    { 
        TextBoxSpellChecker tbSpellChecker = this.radSpellChecker1.GetControlSpellChecker(typeof(RadTextBoxControl)) as TextBoxSpellChecker;  
        MatchCollection words = wordParser.Matches(this.radTextBox1.Text);
        bool containsError = false;
        foreach (Match word in words)
        {
            string text = word.Captures[0].Value;
            if (!tbSpellChecker.SpellChecker.CheckWordIsCorrect(text, System.Threading.Thread.CurrentThread.CurrentCulture))              
            {
                containsError = true;
                break;
            }
        }
        if (!containsError)
        {
            menu.Show(this.radTextBox1, new Point(0,0));
        }
    }
}
0 comments