Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Subclassing the ShapeNode (Read 1562 times)
BudMan
YaBB Newbies
*
Offline


Credidi me felem vidisse

Posts: 45
Joined: Jul 14th, 2007
Subclassing the ShapeNode
Mar 31st, 2010 at 4:19pm
Print Post  
I created a subclass of the ShapeNode class as follows:

               Public Class MyShapeNode
         Inherits ShapeNode
End Class

The reason I did this is because I want to add properties to the MyShapeNode class that the base class does not have.

To instantiate a MyShapeNode object I then wrote code like this:

Dim fnode As MyShapeNode = CType(dgmMain.Factory.CreateShapeNode(pt.X, pt.Y, 20, 20), MyShapeNode)

The text editor accepted the code, but when I ran the program, it threw an InvalidCastException. Maybe I need to go back to OOP school, but should this not work?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Subclassing the ShapeNode
Reply #1 - Mar 31st, 2010 at 5:57pm
Print Post  
The Factory methods create items only from the standard node classes. You can add an instance of a custom class to the diagram through the Nodes collection:

gdmMain.Nodes.Add(New MyShapeNode(...))

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
BudMan
YaBB Newbies
*
Offline


Credidi me felem vidisse

Posts: 45
Joined: Jul 14th, 2007
Re: Subclassing the ShapeNode
Reply #2 - Mar 31st, 2010 at 8:59pm
Print Post  
That did the trick. I wrote the following as a replacement for the Factory.CreateShapeNode method that accommodates subclasses:

               fnode = New MyShapeNode
               dgmMain.Nodes.Add(fnode)
               fnode.Bounds = New RectangleF(pt.X, pt.Y, 20, 20)

This way I can subsequently assign values to the subclass' properties.

Thanks again for the quick response.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint