private void treeView1_ItemDrag(object sender, ItemDragEventArgs e) { if (e.Button != MouseButtons.Left) return; //Ignore non-TreeNode objects being dragged if (!(e.Item is TreeNode)) return; //Get the dragged item from the event var SelectedNode = e.Item as TreeNode; Node Node = null; if ((string)SelectedNode.Tag == "Action") { var Action = DotaActionFactory.CreateNewAction(SelectedNode.Text); Node = new ActionNode(Action); } if ((string)SelectedNode.Tag == "Event") { var Event = DotaData.Events.FirstOrDefault(x => x.ClassName == SelectedNode.Text); Node = new EventNode(Event, Ability.ActionList.GetOrCreateCollection(Event)); } if ((string)SelectedNode.Tag == "Variable") { var Var = Ability.ActionList.Variables.First(x => x.Name == (string)SelectedNode.Text); Node = new VariableNode(Var); } if((string)SelectedNode.Tag == "Target") { var Target = new TargetKey(); if (SelectedNode.Name == "line") { Target.Shape = TargetKey.ShapeE.LINE; } else if(SelectedNode.Name == "circle") { Target.Shape = TargetKey.ShapeE.CIRCLE; } Node = new CustomTargetNode(SelectedNode.Name, Target); } //The node can be null if an item with an unknown tag was drag-dropped if (Node != null) { Node.Location = new PointF(0, 0); this.DoDragDrop(Node, DragDropEffects.Copy); } }
private void treeView1_ItemDrag(object sender, ItemDragEventArgs e) { if (e.Button != MouseButtons.Left) return; var SelectedNode = treeView1.SelectedNode; if (SelectedNode == null) return; //If we don't have a selection, don't bother with this. Node Node = null; if ((string)SelectedNode.Tag == "Action") { var Action = DotaActionFactory.CreateNewAction(SelectedNode.Text); Node = new ActionNode(Action); } if ((string)SelectedNode.Tag == "Event") { var Event = DotaData.Events.FirstOrDefault(x => x.ClassName == SelectedNode.Text); Node = new EventNode(Event, Ability.ActionList.GetOrCreateCollection(Event)); } if ((string)SelectedNode.Tag == "Variable") { var Var = Ability.ActionList.Variables.First(x => x.Name == (string)SelectedNode.Text); Node = new VariableNode(Var); } if((string)SelectedNode.Tag == "Target") { var Target = new TargetKey(); if (SelectedNode.Name == "line") { Target.Shape = TargetKey.ShapeE.LINE; } else if(SelectedNode.Name == "circle") { Target.Shape = TargetKey.ShapeE.CIRCLE; } Node = new CustomTargetNode(SelectedNode.Name, Target); } Node.Location = new PointF(0, 0); this.DoDragDrop(Node, DragDropEffects.Copy); }