Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Menu, Application Menu, Context Menu > Hide RadContextMenu

Answered Hide RadContextMenu

Feed from this thread
  • Jack avatar

    Posted on Apr 7, 2011 (permalink)

    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.


       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;
                        }
                    }
                }
            }
    Attached files

    Reply

  • Jack avatar

    Posted on Apr 7, 2011 (permalink)

    Hi,

    I think I got a little bit close by doing the following. Still need to find out a way to hide the RadContextMenu before the control gets into the mouseup event.

    private void rtbComments_MouseUp(object sender, MouseEventArgs e)
         {
             if (e.Button == MouseButtons.Right)
             {
                 if (rtbComments.SelectionLength > 0)
                 {
                     radContextMenuManager1.SetRadContextMenu(rtbComments, cMenuComments);
                 }
                 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)
                     {
                         radContextMenuManager1.SetRadContextMenu(rtbComments, cMenuComments);
                     }
                     else
                     {
                         radContextMenuManager1.SetRadContextMenu(rtbComments, null);
                     }
                 }
             }
         }

    Reply

  • Answer Ivan Todorov Ivan Todorov admin's avatar

    Posted on Apr 12, 2011 (permalink)

    Hello Jack,

    Thank you for writing.

    I would suggest the following approach:

    void cMenuComments_DropDownOpening(object sender, CancelEventArgs e)
    {
        Point location = this.rtbComments.PointToClient(Control.MousePosition);
        if (SpellCheck(location))
        {
            e.Cancel = true;
        }
    }

    The idea behind it is to do your logic in the DropDownOpening event and cancel it if needed. This way you won't have to set and unset context menus to the context menu manager and the popup won't show neither.

    I hope you find this useful. If you need further help, do not hesitate to write back.

    Best wishes,
    Ivan Todorov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Jack avatar

    Posted on Apr 12, 2011 (permalink)

    Hi Ivan,

    That did work. Thanks a lot. I have one other question related to RadContextMenu in a RadGridView 

    I am using a ColumnChooser and a RadContextMenu on a RadGridView . How do I hide the RadContextMenu  when the user clicks on the column header. 

    Following is the code I am currently using which does work but I would like to use the DropDownOpening event of cMenuReports to hide it since that seems to be a cleaner way of doing things as you suggested earlier.


    So, the bottom line is how do I know if the user right clicked on a column or a cell in the DropDownOpening event of cMenuReports.

    The attached image should give you an idea of the problem.(RadContextMenu on top of ColumnChooser)

    private void rgvReports_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
    {
            if (e.ContextMenuProvider is GridHeaderCellElement)
            {
                radContextMenuManager1.SetRadContextMenu(rgvReminders, null);
            }
            else
            {
                radContextMenuManager1.SetRadContextMenu(rgvReminders, cMenuReports);
            }
    }
    Attached files

    Reply

  • Answer Ivan Todorov Ivan Todorov admin's avatar

    Posted on Apr 15, 2011 (permalink)

    Hello Jack,

    I am glad I could help.

    As to your question, here is the approach I would suggest:

    void radContextMenu1_DropDownOpening(object sender, CancelEventArgs e)
    {
        Point mouseLocation = radGridView1.PointToClient(Control.MousePosition);
        RadElement elementUnderMouse = radGridView1.ElementTree.GetElementAtPoint(mouseLocation);
     
        if (elementUnderMouse is GridHeaderCellElement)
        {
            e.Cancel = true;
        }
    }

    In general, this code shows how you can get the element of the grid which is under the mouse pointer. When you have this element you can check its type and decide whether you want to cancel the dropdown. You can check the type of a cell by spying it with our RadControlSpy tool. More information about using it can be found here.

    I hope this will help you. Do not hesitate to contact me if you have any additional questions.

    Best wishes,
    Ivan Todorov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Jack avatar

    Posted on Apr 15, 2011 (permalink)

    Thanks Ivan,

    It worked perfectly.

    Reply

  • Ivan Todorov Ivan Todorov admin's avatar

    Posted on Apr 20, 2011 (permalink)

    Hello Jack,

    I am glad I could help. If you have any additional questions, feel free to contact me.

    Greetings,
    Ivan Todorov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Menu, Application Menu, Context Menu > Hide RadContextMenu
Related resources for "Hide RadContextMenu"

[ Features | Demos | Documentation | Knowledge Base | Telerik TV | Code Library | Step-by-step Tutorial | Blogs | Self-Paced Trainer ]