/// <summary> /// Selects the item sent as a parameter /// </summary> /// <param name="element">Item to select</param> private void SelectElement(GraphElement element) { //The item is selected element.Selected = true; //The element is loaded into the temporary layer this.selectLayer.AddElement(element); if (GraphDiagram.ValidateCopy(this.selectLayer.Elements)) { this.miCopy.Enabled = true; this.miCut.Enabled = true; } else { if (this.OperationDisabled != null) { this.OperationDisabled(this, new OperationEventArgs(Operation.Copy)); this.OperationDisabled(this, new OperationEventArgs(Operation.Cut)); } this.miCopy.Enabled = false; this.miCut.Enabled = false; } if (GraphDiagram.ValidateDelete(this.selectLayer.Elements)) { this.miRemove.Enabled = true; } else { if (this.OperationDisabled != null) { this.OperationDisabled(this, new OperationEventArgs(Operation.Delete)); } this.miRemove.Enabled = false; } if (GraphDiagram.ValidateSettings(this.selectLayer.Elements)) { this.miSettings.Enabled = true; } else { if (this.OperationDisabled != null) { this.OperationDisabled(this, new OperationEventArgs(Operation.Settings)); } this.miSettings.Enabled = false; } }
public void MouseUp(MouseEventArgs e) { //When the left mouse button is released... if (e.Button == MouseButtons.Left) { //You get the upper left point of the selection box and the size Point location = new Point(Math.Min(this.initialPoint.X, e.X), Math.Min(this.initialPoint.Y, e.Y)); Size size = new Size(Math.Abs(e.X - this.initialPoint.X), Math.Abs(e.Y - this.initialPoint.Y)); //A Rectangle object is created that contains the two informations Rectangle rectangle = new Rectangle(location, size); //The items inside the selection box are selected this.SelectElements(rectangle); //The chart selection box is deleted this.tempLayer.ClearAndHide(); this.selectionRectangle.Dispose(); //The temporary layer is updated this.tempLayer.UpdateSurface(); if (GraphDiagram.ValidateCopy(this.selectLayer.Elements)) { } else { if (this.OperationDisabled != null) { this.OperationDisabled(this, new OperationEventArgs(Operation.Copy)); this.OperationDisabled(this, new OperationEventArgs(Operation.Cut)); } } if (GraphDiagram.ValidateDelete(this.selectLayer.Elements)) { } else { if (this.OperationDisabled != null) { this.OperationDisabled(this, new OperationEventArgs(Operation.Delete)); } } if (GraphDiagram.ValidateSettings(this.selectLayer.Elements)) { } else { if (this.OperationDisabled != null) { this.OperationDisabled(this, new OperationEventArgs(Operation.Settings)); } } //Exception is thrown for change of operation depending on whether there are selected items if (this.selectLayer.Elements.Count == 0) { this.selectLayer.Visible = false; throw new OperationException(Operation.SelectRectangle, "Change to Nop Operation"); } else { if (this.ElementSelectedChanged != null) { this.ElementSelectedChanged(this, new EventArgs()); } throw new OperationException(Operation.SelectRectangle, "Change to Select Operation"); } } }