Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Cannot copy attched shapes (Read 3600 times)
srlevitt
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Mar 27th, 2007
Cannot copy attched shapes
Apr 19th, 2008 at 1:54pm
Print Post  
I followed an example from a previous thread so I could have labels underneath my ShapeNodes. I created a descendant of ShapeNode which creates and attaches a label, e.g.

[code]

    class MyShape : ShapeNode
    {
       Diagram diagram;
       public MyShape(Diagram d)
           : base(d)
       {
           diagram = d;

           ShapeNode label = new ShapeNode(d);
           label.Text = "label text";
           label.Bounds = new RectangleF(PointF.Empty,
                                       d.MeasureString(label.Text, label.Font, int.MaxValue, label.TextFormat));
           label.Transparent = true;
           label.Locked = true;
           d.Nodes.Add(label);

           // attach the label to the icon
           RectangleF rc1 = this.Bounds;
           RectangleF rc2 = label.Bounds;
           label.Bounds = new RectangleF(
                                   rc1.Left + rc1.Width / 2 - rc2.Width / 2,
                                   rc1.Bottom + 1,
                                   rc2.Width, rc2.Height);
           label.AttachTo(this, AttachToNode.BottomCenter);
           this.SubordinateGroup.FollowMasterContainment = true;
       }
    }[/code]

That all works OK. When I try to select and copy a "MyShape" using View.CopyToClipboard or CutToClipboard, I get an exception:

"Value cannot be null.\r\nParameter name: value"

   at System.Collections.CollectionBase.OnValidate(Object value)
   at System.Collections.CollectionBase.System.Collections.IList.set_Item(Int32 index, Object value)
   at MindFusion.Diagramming.DiagramItemCollection.set_Item(Int32 index, DiagramItem value)
   at MindFusion.Diagramming.Diagram.CopySelection(Diagram source, Boolean unconnectedLinks, Boolean copyGroups)
   at MindFusion.Diagramming.WinForms.DiagramView.CopyToClipboard(Boolean persist, Boolean groups)
   at MindFusion.Diagramming.WinForms.DiagramView.CopyToClipboard(Boolean persist)
   at MindFusion.Diagramming.WinForms.DiagramView.CutToClipboard(Boolean copy)


Is there a property I am not setting?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Cannot copy attched shapes
Reply #1 - Apr 21st, 2008 at 8:35am
Print Post  
Have you added a Clone method or a copy-constructor to the MyShape class?
  
Back to top
 
IP Logged
 
srlevitt
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Mar 27th, 2007
Re: Cannot copy attched shapes
Reply #2 - Apr 21st, 2008 at 8:39am
Print Post  
No, do I need to?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Cannot copy attched shapes
Reply #3 - Apr 21st, 2008 at 8:59am
Print Post  
Yes, it is required if you need clipboard support.
  
Back to top
 
IP Logged
 
srlevitt
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Mar 27th, 2007
Re: Cannot copy attched shapes
Reply #4 - Apr 21st, 2008 at 8:01pm
Print Post  
I tried to implement a copy constructor like:
Code
Select All
	  public MyShape(MyShape original)
		: base(original)
	  {
		diagram = original.diagram;
	  }
 


This stops the copyToClipboard crashing, but when I paste from the clipboard, it comes back as a ShapeNode. Why is this?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Cannot copy attched shapes
Reply #5 - Apr 21st, 2008 at 9:11pm
Print Post  
Call Diagram.RegisterItemClass(typeof(MyShape), "MyShapeID", 1); in your form's constructor. Otherwise, the serialization code will process your objects as ShapeNodes.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint