/// <summary> /// Handles the DragDrop event of contained RichTextBox object. /// Process text changes on drop event. /// </summary> /// <param name="sender">The reference to contained RichTextBox object.</param> /// <param name="e">The event arguments.</param> void OnDragDrop(object sender, DragEventArgs e) { // Check if the picked item is the one we added to the toolbox. if (e.Data.GetDataPresent(typeof(Toolbox_TestItem1))) { GraphEditorPackage.PutTextToCS("Console.WriteLine(\"T1\");"); Toolbox_TestItem1 myData = (Toolbox_TestItem1)e.Data.GetData(typeof(Toolbox_TestItem1)); UserControl_Node n = new UserControl_Node("T1"); n.Location = this.PointToClient(Cursor.Position); this.Controls.Add(n); // Specify DragDrop result e.Effect = DragDropEffects.Copy; } else if (e.Data.GetDataPresent(typeof(Toolbox_TestItem2))) { GraphEditorPackage.PutTextToCS("Console.WriteLine(\"T2\");"); UserControl_Node n = new UserControl_Node("T2"); n.Location = this.PointToClient(Cursor.Position); this.Controls.Add(n); // Specify DragDrop result e.Effect = DragDropEffects.Copy; } else if (e.Data.GetData(DataFormats.StringFormat).ToString().StartsWith("UserControl_Node")) { string s = e.Data.GetData(DataFormats.StringFormat).ToString(); string[] tokens = s.Split('|'); string GuidString = tokens[1]; foreach (Control c in this.Controls) { if (c.GetType() == typeof(UserControl_Node)) { UserControl_Node uc = (UserControl_Node)c; if (uc.Guid.ToString() == GuidString) { Point newPlace = new Point( Cursor.Position.X - uc.PointMouseDown.X , Cursor.Position.Y - uc.PointMouseDown.Y); uc.Location = this.PointToClient(newPlace); } } } // Specify DragDrop result e.Effect = DragDropEffects.Move; } }
void save(string fileName) { GraphEditorPackage.GetProjectName(fileName); string s = ""; foreach (Control c in editorControl.Controls) { if (c.GetType() == typeof(UserControl_Node)) { UserControl_Node x = (UserControl_Node)c; s += x.Guid + Environment.NewLine; } else { throw new Exception("unknown control detected while saving"); } } System.IO.File.WriteAllText(fileName, s); }
private void GraphEditorControl_DragOver(object sender, DragEventArgs e) { // Check if the picked item is the one we added to the toolbox. if (e.Data.GetDataPresent(typeof(Toolbox_TestItem1))) { } else if (e.Data.GetDataPresent(typeof(Toolbox_TestItem2))) { } else if (e.Data.GetData(DataFormats.StringFormat).ToString().StartsWith("UserControl_Node")) { string s = e.Data.GetData(DataFormats.StringFormat).ToString(); string[] tokens = s.Split('|'); string GuidString = tokens[1]; foreach (Control c in this.Controls) { if (c.GetType() == typeof(UserControl_Node)) { UserControl_Node uc = (UserControl_Node)c; if (uc.Guid.ToString() == GuidString) { Point newPlace = new Point( Cursor.Position.X - uc.PointMouseDown.X , Cursor.Position.Y - uc.PointMouseDown.Y); uc.Location = this.PointToClient(newPlace); } } } // Specify DragDrop result e.Effect = DragDropEffects.Move; } }