Hi,
I am using a RadContextMenu and a spell checker on a richtextbox. When I right click on text, the RadContextMenu and the spell check menu are showing up. I want to hide the RadContextMenu when a user right clicks.
Following is the code I am using to accomplish that, but I think this is not the right way as a horizontal line shows up when I try to collapse the menu items part of the RadContextMenu. Also for the first time the RadContextMenu shows up even before I get into the mouseup event.
Please suggest me a way to hide the RadContextMenu.
I am using a RadContextMenu and a spell checker on a richtextbox. When I right click on text, the RadContextMenu and the spell check menu are showing up. I want to hide the RadContextMenu when a user right clicks.
Following is the code I am using to accomplish that, but I think this is not the right way as a horizontal line shows up when I try to collapse the menu items part of the RadContextMenu. Also for the first time the RadContextMenu shows up even before I get into the mouseup event.
Please suggest me a way to hide the RadContextMenu.
private void rtbComments_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (rtbComments.SelectionLength > 0)
{
mnuCut.Visibility = ElementVisibility.Visible;
mnuCopy.Visibility = ElementVisibility.Visible;
mnuPaste.Visibility = ElementVisibility.Visible;
}
else
{
// Check if the words under the cursor are misspelled.
int x = SpellingCheckerEngine.CheckCtrlBackgroundMenu(rtbComments.Handle, e.X, e.Y, RTB1Options, RTB1MarkColor);
// If there were no misspelled words under the cursor, popup the copy menu.
if (x == 0)
{
mnuCut.Visibility = ElementVisibility.Visible;
mnuCopy.Visibility = ElementVisibility.Visible;
mnuPaste.Visibility = ElementVisibility.Visible;
}
else
{
mnuCut.Visibility = ElementVisibility.Collapsed;
mnuCopy.Visibility = ElementVisibility.Collapsed;
mnuPaste.Visibility = ElementVisibility.Collapsed;
}
}
}
}
{
if (e.Button == MouseButtons.Right)
{
if (rtbComments.SelectionLength > 0)
{
mnuCut.Visibility = ElementVisibility.Visible;
mnuCopy.Visibility = ElementVisibility.Visible;
mnuPaste.Visibility = ElementVisibility.Visible;
}
else
{
// Check if the words under the cursor are misspelled.
int x = SpellingCheckerEngine.CheckCtrlBackgroundMenu(rtbComments.Handle, e.X, e.Y, RTB1Options, RTB1MarkColor);
// If there were no misspelled words under the cursor, popup the copy menu.
if (x == 0)
{
mnuCut.Visibility = ElementVisibility.Visible;
mnuCopy.Visibility = ElementVisibility.Visible;
mnuPaste.Visibility = ElementVisibility.Visible;
}
else
{
mnuCut.Visibility = ElementVisibility.Collapsed;
mnuCopy.Visibility = ElementVisibility.Collapsed;
mnuPaste.Visibility = ElementVisibility.Collapsed;
}
}
}
}