Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
HI all

I have created a library of code that uses graph searching, and would like to display a label for each node in the graph.

The label control code was created by Microsoft, so it is a sealed unit. I would like the have it such that when a user clicks on the label, the node object associated with the label is updated.

Something like:

C#
class AStarGridSearchLabel: System.Windows.Forms.Label, AStarGridSearchItem
{
}


AStarGridSearchItem inherits from the AStarSearchElement.

The basic scheme I have is an A* search where I have AStarSearchElements and an AStarSearchAgent.
I then created a AStarSearchGrid that contains AStarGridSearchItem.
Now I want to display this on a form without having to rewrite lots of extraneous code.

AStarGridSearchItem is a concrete class and so is the System.Windows.Forms.Label.

Any ideas on how I can achieve this?

Thanks
MT
Posted
Comments
TrushnaK 13-Aug-13 9:32am    
Sealed class can not be inherited.
Bernhard Hiller 13-Aug-13 9:34am    
"Label" is not sealed.

1 solution

Multiple inheritance is not supported by C#

Why doesn't C# support multiple inheritance?[^]

What you could do is wrap the AStarGridSearchItem class in AStarGridSearchLabel and implement an interface, e.g.

C#
interface IStarGridSearchItem
{
    void Foo();
}

class AStarGridSearchItem
{
    public void Foo() { /* ... */ }
}

class AStarGridSearchLabel : Label, IStarGridSearchItem
{
    private AStarGridSearchItem _item = new AStarGridSearchItem() ;

    // Implement the interface, and wrap AStarGridSearchItem
    public void Foo()
    {
        _item.Foo();
    }
}
 
Share this answer
 
Comments
ridoy 13-Aug-13 9:03am    
good answer,5ed!
Sergey Alexandrovich Kryukov 13-Aug-13 10:56am    
5ed. Just a note: this kind of inheritance is sometimes referred as "weak form of multiple inheritance". This is a traditional compromise between really problematic multiple inheritance and pure single inheritance.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900