public ShapeNode MakeNode(float x, float y, float width, float height) { ShapeNode note = diagramView1.Diagram.Factory.CreateShapeNode(x, y, width, height); note.Tag = ""; note.HyperLink = ""; note.Selected = true; //adjust the box properties ProxyNode node = new ProxyNode(note); node.FillColor = NodeFillColor; node.FrameColor = NodeFrameColor; node.FrameThickness = NodeFrameThickness; node.SnapToGrid(); return note; }
public void KeyDownHandler(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.X && e.Modifiers == Keys.Control) { Cut(); return; } if (e.KeyCode == Keys.C && e.Modifiers == Keys.Control) { Copy(); return; } if (e.KeyCode == Keys.V && e.Modifiers == Keys.Control) { Paste(); return; } if (e.KeyCode == Keys.Z && e.Modifiers == Keys.Control) { diagramView1.Diagram.UndoManager.Undo(); return; } if (e.KeyCode == Keys.Y && e.Modifiers == Keys.Control) { diagramView1.Diagram.UndoManager.Redo(); return; } if (e.KeyCode == Keys.A && e.Modifiers == Keys.Control) { SelectAll(); return; } if (e.KeyCode == Keys.Back) { if (diagramView1.Diagram.Selection.Nodes.Count > 0) { DiagramNode node = diagramView1.Diagram.Selection.Nodes[0]; diagramView1.Diagram.Nodes.Remove(node); } return; } DiagramItemCollection selectedItems = diagramView1.Diagram.Selection.Items; if (e.KeyCode == Keys.S) { foreach (DiagramItem selectedItem in selectedItems) { if (selectedItem is ShapeNode) { ShapeNode selectedBox = (ShapeNode)selectedItem; float selectedBoxNewX, selectedBoxNewY; selectedBoxNewX = selectedBox.Bounds.X; selectedBoxNewY = selectedBox.Bounds.Y + 8; selectedBox.Move(selectedBoxNewX, selectedBoxNewY); } } return; } if (e.KeyCode == Keys.W) { foreach (DiagramItem selectedItem in selectedItems) { if (selectedItem is ShapeNode) { ShapeNode selectedBox = (ShapeNode)selectedItem; float selectedBoxNewX, selectedBoxNewY; selectedBoxNewX = selectedBox.Bounds.X; selectedBoxNewY = selectedBox.Bounds.Y - 8; selectedBox.Move(selectedBoxNewX, selectedBoxNewY); //if auto resize is enabled and the new position is outside document bounds //resize the document to fit the moved item //if(selectedBoxNewY>datagram. //datagram.ResizeToFitItem(selectedBox); } } return; } if (e.KeyCode == Keys.A) { foreach (DiagramItem selectedItem in selectedItems) { if (selectedItem is ShapeNode) { ShapeNode selectedBox = (ShapeNode)selectedItem; float selectedBoxNewX, selectedBoxNewY; selectedBoxNewX = selectedBox.Bounds.X - 8; selectedBoxNewY = selectedBox.Bounds.Y; selectedBox.Move(selectedBoxNewX, selectedBoxNewY); //if auto resize is enabled and the new position is outside document bounds //resize the document to fit the moved item //if(selectedBoxNewY>datagram. //datagram.ResizeToFitItem(selectedBox); } } return; } if (e.KeyCode == Keys.D) { foreach (DiagramItem selectedItem in selectedItems) { if (selectedItem is ShapeNode) { ShapeNode selectedBox = (ShapeNode)selectedItem; float selectedBoxNewX, selectedBoxNewY; selectedBoxNewX = selectedBox.Bounds.X + 8; selectedBoxNewY = selectedBox.Bounds.Y; selectedBox.Move(selectedBoxNewX, selectedBoxNewY); //if auto resize is enabled and the new position is outside document bounds //resize the document to fit the moved item //if(selectedBoxNewY>datagram. //datagram.ResizeToFitItem(selectedBox); } } return; } if (e.KeyCode == Keys.Oemplus) { foreach (DiagramItem selectedItem in selectedItems) { if (selectedItem is ShapeNode) { ShapeNode selectedBox = (ShapeNode)selectedItem; ProxyNode node = new ProxyNode(selectedBox); node.SnapToGrid(); node.IncreaseWidthByGrid(); } } return; } if (e.KeyCode == Keys.OemMinus) { foreach (DiagramItem selectedItem in selectedItems) { if (selectedItem is ShapeNode) { ShapeNode selectedBox = (ShapeNode)selectedItem; ProxyNode node = new ProxyNode(selectedBox); node.SnapToGrid(); node.DecreaseWidthByGrid(); } } return; } }
/// <summary> /// Paste object(s) from clipboard. /// </summary> public void Paste() { if (editing) { ((TextBox)editControl).Paste(); } else if (diagramView1.Diagram.Selection.Nodes.Count == 1 && Clipboard.ContainsText()) { if (diagramView1.Diagram.Selection.Nodes[0] is ShapeNode) { ShapeNode node = (ShapeNode)diagramView1.Diagram.Selection.Nodes[0]; if (node.Text == "" && Clipboard.ContainsText()) node.Text = Clipboard.GetText(); } } else { diagramView1.PasteFromClipboard(dX, dY); dX += 0; //Fix a strange font bug and increase the offsets by the size of the pasted object(s). foreach (ShapeNode note in diagramView1.Diagram.Selection.Nodes) { note.Font = note.Font; dY += (int)note.Bounds.Height; ProxyNode node = new ProxyNode(note); node.SnapToGrid(); } } }