Пример #1
0
        /// <summary>
        ///   Handles the Paste event by pasting an <see cref="VGElement" /> from the
        ///   clipboard into the picture.
        /// </summary>
        public override void OnPaste()
        {
            // Retrieves the data from the clipboard.
            var test = Clipboard.GetData(DataFormats.StringFormat);

            if (test == null)
            {
                return;
            }

            var t = VGElement.Deserialize(test.ToString());

            // Determines whether the data is in a format you can use.
            if (t != null)
            {
                var elementToAdd = t;
                this.ResetSelectedElement();

                if (!this.Elements.Contains(elementToAdd))
                {
                    // New Graphic element created, so notify listeners.
                    this.OnShapeAdded(new ShapeEventArgs(elementToAdd));
                }
            }
        }
Пример #2
0
        ///////////////////////////////////////////////////////////////////////////////
        // Inherited methods                                                         //
        ///////////////////////////////////////////////////////////////////////////////
        #region OVERRIDES

        /// <summary>
        /// Overridden. This custom on paste invokes a dialog that switches
        /// between target and default stimulus element insertion.
        /// </summary>
        public override void OnPaste()
        {
            // Retrieves the data from the clipboard.
            object test = Clipboard.GetData(DataFormats.StringFormat);

            if (test == null)
            {
                return;
            }

            VGElement t = VGElement.Deserialize(test.ToString());

            // Determines whether the data is in a format you can use.
            if (t != null)
            {
                VGElement elementToAdd = t;
                this.ResetSelectedElement();

                PasteAsDialog dialog = new PasteAsDialog();
                dialog.ElementToPaste = elementToAdd;

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    if (!this.Elements.Contains(elementToAdd))
                    {
                        if (dialog.IsTarget)
                        {
                            int count = this.GetNextTargetNumber();
                            elementToAdd.Name          = "Target" + count.ToString();
                            elementToAdd.StyleGroup    = VGStyleGroup.AOI_TARGET;
                            elementToAdd.Pen           = this.TargetPen;
                            elementToAdd.Font          = this.TargetFont;
                            elementToAdd.FontColor     = this.TargetFontColor;
                            elementToAdd.TextAlignment = this.TargetTextAlignment;
                        }
                        else
                        {
                            elementToAdd.StyleGroup = VGStyleGroup.None;
                        }
                    }

                    this.Elements.Add(elementToAdd);
                    this.SelectedElement = elementToAdd;

                    // New Graphic element created, so notify listeners.
                    this.OnShapeAdded(new ShapeEventArgs(elementToAdd));
                    this.DrawForeground(false);
                }
            }
        }