/// <summary> /// Paste /// </summary> private void pasteToolStripMenuItem_Click(object sender, EventArgs e) { if (!Clipboard.ContainsText(TextDataFormat.Text)) { return; } // get text var tdata = Clipboard.GetText(); using (var sr = new StringReader(tdata)) { var copiedData = new XmlSerializer(typeof(OmrTemplate)).Deserialize(sr) as OmrTemplate; var newSelection = new ShapeCollection(); foreach (var copyData in copiedData.Fields) { // Copy the template data var tData = copyData.Clone() as OmrQuestionField; tData.Id = Guid.NewGuid().ToString(); // Constructor var shp = m_canvas.FindShape(copyData.Id); ConstructorInfo ci = null; if (shp != null) { ci = shp.GetType().GetConstructor(new[] { tData.GetType() }); } else { if (tData is OmrBarcodeField) { ci = typeof(BarcodeFormFieldStencil).GetConstructor(new[] { tData.GetType() }); } else if (tData is OmrBubbleField) { ci = typeof(BubbleFormFieldStencil).GetConstructor(new[] { tData.GetType() }); } } if (ci == null) { MessageBox.Show(string.Format("Could not paste object {0}", tData.Id)); continue; } var clone = ci.Invoke(new object[] { tData }) as IShape; if (shp != null) { clone.Position = new PointF(shp.Position.X + 10, shp.Position.Y + 10); clone.Size = new SizeF(shp.Size.Width, shp.Size.Height); } else { clone.Position = tData.TopLeft; clone.Size = new SizeF(tData.BottomRight.X - tData.TopLeft.X, tData.BottomRight.Y - tData.TopLeft.Y); } clone.Tag = tData; m_currentTemplate.Fields.Add(tData); newSelection.Add(clone); m_canvas.Add(clone); } m_canvas.ClearSelection(); m_canvas.SelectedShapes.AddRange(newSelection); } }