Context Menu with sub menus via designer

7 posts, 1 answers
  1. Brendan
    Brendan avatar
    52 posts
    Member since:
    Dec 2011

    Posted 23 Oct 2014 Link to this post

    Is it possible to create a right click Rad context menu in the designer with submenu items?  Or can it only be done in code.

    Is there any suitable rad menu that can be created in the designer with sub menus and be used as a right click menu?

    Otherwise I can use the standard .Net menu I guess.

    Thanks
  2. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 24 Oct 2014 Link to this post

    Hi Brendan,

    Thank you for writing.

    Yes it is possible, first drag and drop RadContextMenu onto the form (the menu is added at the bottom left corner - see step 1 image). Then you can just open the smart tag (step 2 image, click the edit items link and add some items to the menu (see the step 3 image). 

    Please let me know if there is something else I can help you with. 
     
    Regards,
    Dimitar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Brendan
    Brendan avatar
    52 posts
    Member since:
    Dec 2011

    Posted 24 Oct 2014 in reply to Dimitar Link to this post

    Hi Dimitar, I am familiar with the RadContextMenu, it Is the sub menus that I am having trouble with.  Please see the attached image that I created with the Microsoft ContextMenuStrip.  How do I create the same submenu items in the RadContextMenu designer?

    If I do it through code do I need to dispose of all the RadContextMenu items every time the menu is closed?  If I don't will this lead to increased memory usage?

    Thanks.
  5. Answer
    Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 27 Oct 2014 Link to this post

    Hello Brendan,

    Thank you for writing back.

    Each RadMenuItem has its own collection of items (first attached image) and you can add items to it in the very same way (second attached image). The result will look like in the third attached image.

    Creating the items in the designer also creates code for them. It is located in the InitializeComponent method you can see it by opening the forms designer.cs file (the last attached image). In this case the items will be automatically disposed when there are no reference to them and the form is disposed. You do not need to manually dispose the items since they will not consume much memory and recreating them actually can take more memory since the .NET garbage collector in non-deterministic and you cannot tell for sure when the garbage will be collected. 

    I hope this helps.

    Regards,
    Dimitar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Brendan
    Brendan avatar
    52 posts
    Member since:
    Dec 2011

    Posted 27 Oct 2014 in reply to Dimitar Link to this post

    Thanks I see the sub items now
  7. Brendan
    Brendan avatar
    52 posts
    Member since:
    Dec 2011

    Posted 27 Oct 2014 in reply to Dimitar Link to this post

    Hi Dimitar, I wanted to clarify dynamic Context Menu creation instead of using the designer.  If I create a custom menu in code every time a user right clicks a grid do I need to dispose of the menu, its items, and the handlers after the event click, or will garbage collection handle everything?  There could be many clicks during the lifetime session of the program.

    Example;
    Private contextMenu1 As RadContextMenu
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        contextMenu1 = New RadContextMenu()
        Dim menuItem1 As New RadMenuItem("Item 1")
        AddHandler menuItem1.Click, AddressOf rmi1_Click
        Dim menuItem2 As New RadMenuItem("Item 2")
        AddHandler menuItem2.Click, AddressOf rmi2_Click
        contextMenu1.Items.Add(menuItem1)
        contextMenu1.Items.Add(menuItem2)
    End Sub
  8. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 29 Oct 2014 Link to this post

    Hello Brendan,

    Thank you for writing back.

    The memory will be allocated when the items and the context menu are created and it will be freed once they are not referenced anywhere (or there are out of scope). It will not depend on the number of times the menu is used or how many times the user has clicked on item. More information is available here: Garbage Collection.

    I hope this helps.

    Regards,
    Dimitar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready