Drag from RadMenuItem

6 posts, 0 answers
  1. Laura
    Laura avatar
    11 posts
    Member since:
    Jan 2014

    Posted 07 Dec 2015 Link to this post

    I create a RadMenu in a MDI Parent form dynamically.  Each menu item has a tag property with a value that references a string.  I also have a form that is open that has a Split Container, Panel and within the panel, a Panorama object with a PanelGroup, ready to add a tile.  I would like to drag from the RadMenuItem and drop into the PanelGroup and create a tile that has a reference (can also be the Tile's tag).  

     I already have this working when I drag from a TreeView to create a tile, as well as dragging from a desktop shortcut...   Although I can set the RadMenuItem.AllowDrag property = true, I don't see anyway to trigger and work with this...

  2. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 08 Dec 2015 Link to this post

    Hello Laura,

    Thank you for writing.

    The following example shows how you can perform a drag and drop operation between RadMenu and RadPanorama:
    public Form1()
    {
        InitializeComponent();
        foreach (var item in radMenu1.Items)
        {
            item.AllowDrag = true;
            item.MouseDown += Item_MouseDown;
            
        }
     
        radPanorama1.AllowDrop = true;
        radPanorama1.DragDrop += RadPanorama1_DragDrop;
        radPanorama1.DragEnter += RadPanorama1_DragEnter;
    }
     
    private void RadPanorama1_DragEnter(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.Move;
    }
     
    private void RadPanorama1_DragDrop(object sender, DragEventArgs e)
    {
        RadMenuItem draggedItem = e.Data.GetData(typeof(RadMenuItem)) as RadMenuItem;
        RadTileElement tile = new RadTileElement();
        tile.Text = draggedItem.Text;
        radPanorama1.Items.Add(tile);
    }
     
    private void Item_MouseDown(object sender, MouseEventArgs e)
    {
        var item = sender as RadMenuItem;
        radMenu1.DoDragDrop(item, DragDropEffects.Move);
    }

    Could you please check and let me know how it fit's in your case?

    I am looking forward to your reply.

    Regards,
    Dimitar
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Laura
    Laura avatar
    11 posts
    Member since:
    Jan 2014

    Posted 09 Dec 2015 in reply to Dimitar Link to this post

    This allowed me to drag/drop perfectly, but I have a residual problem in that now the click event is not firing.  On the menu item click event, I have a form opening.  This is not occurring when I have the DoDragDrop coded.
  5. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 10 Dec 2015 Link to this post

    Hello Laura,

    Thank you for writing back.

    You can start the drag drop in the MouseMove event instead:
    private Point mouseDownPosition;
     
    private void Item_MouseDown(object sender, MouseEventArgs e)
    {
        this.mouseDownPosition = e.Location;
    }
     
    void item_MouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button != MouseButtons.Left)
        {
            return;
        }
        if (IsRealDrag(mouseDownPosition, e.Location))
        {
            var item = sender as RadMenuItem;
            radMenu1.DoDragDrop(item, DragDropEffects.Move);
        }
    }

    Please let me know if there is something else I can help you with. 
     
    Regards,
    Dimitar
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  6. Laura
    Laura avatar
    11 posts
    Member since:
    Jan 2014

    Posted 10 Dec 2015 in reply to Dimitar Link to this post

    I am getting an error on the IsRealDrag method - does not exist in the current context...  here is my code (where loNew = the RadMenuItem and mainMenuStrip is the RadMenu object):

     private void loNew_MouseMove(object sender, MouseEventArgs e)
            {
                if (e.Button != MouseButtons.Left)
                {
                    return;
                }
                if (IsRealDrag(mouseDownPosition, e.Location))
                {
                    var item = sender as RadMenuItem;
                    mainMenuStrip.DoDragDrop(item, DragDropEffects.Move);
                }

            }

  7. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 10 Dec 2015 Link to this post

    Hello Laura,

    Apparently I haven't copied the entire snippet. Here is the method:
    private static bool IsRealDrag(Point mousePosition, Point initialMousePosition)
    {
        return (Math.Abs(mousePosition.X - initialMousePosition.X) >= SystemInformation.DragSize.Width) ||
               (Math.Abs(mousePosition.Y - initialMousePosition.Y) >= SystemInformation.DragSize.Height);
    }

    Let me know if you have additional questions.

    Regards,
    Dimitar
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready