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...
5 Answers, 1 is accepted
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
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.
Dimitar
Telerik
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);
}
}
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
