Eyeshot 11 Documentation
WinForms Control / Tutorials / Cloning a custom entity
In This Topic
    Cloning a custom entity
    In This Topic

    This article explains how to clone a custom Line entity. Custom entities can be easily cloned adding the protected copy constructor and overriding the Clone() method. A complete example follows.

     

    class MyLine : Line
    {
       private float price;
    
       public MyLine(double x1, double y1, double x2, double y2, float thePrice)
          : base(x1, y1, x2, y2)
       {
          price = thePrice;
       }
    
       protected MyLine(MyLine another)
          : base(another)
       {
          price = another.price;
       }
    
       public override object Clone()
       {
          return new MyLine(this);
       }
    }
    Class MyLine
       Inherits Line
    
       Private price As Single
    
       Public Sub New(x1 As Double, y1 As Double, x2 As Double, y2 As Double, thePrice As Single)
          MyBase.New(x1, y1, x2, y2)
          price = thePrice
       End Sub
    
       Public Sub New(another As MyLine)
          MyBase.New(another)
          price = another.price
       End Sub
    
       Public Overrides Function Clone() As Object
          Return New MyLine(Me)
       End Function
    
    End Class