问题描述
HI all
我创建了一个使用图搜索的代码库,并希望为图中的每个节点显示一个标签。
标签控制代码由Microsoft创建,因此它是一个密封单元。我想要这样,当用户点击标签时,更新与标签关联的节点对象。
类似于:
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:
class AStarGridSearchLabel: System.Windows.Forms.Label, AStarGridSearchItem
{
}
AStarGridSearchItem继承自AStarSearchElement。
我的基本方案是A *搜索,其中我有AStarSearchElements和AStarSearchAgent。
然后我创建了一个包含AStarGridSearchItem的AStarSearchGrid。
现在我想在表单上显示它,而不必重写大量无关的代码。
AStarGridSearchItem是一个具体的类,System.Windows.Forms.Label也是如此。
Any关于如何实现这个目标的想法?
谢谢
MT
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
推荐答案
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();
}
}
这篇关于C#使用密封类的多重继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!