开发者

shared functionality on usercontrol and form

I need to add shared functionality to both Forms 开发者_运维百科and UserControls. Since multiple inheritance isn't supported in .net I wonder how I best tackle this?

The shared functionality is a dictionary that is filled by the form or usercontrol and then processed.

Regards


public class SharedFunctionality
{
    public void ImportantToCallThisOnLoad();
}

public class MyForm : Form
{
    SharedFunctionality mySharedFunctionality = new SharedFunctionality();

    public void OnLoad()
    {
        mySharedFunctionality.ImportantToCallThisOnLoad();
    }
}

public class MyControl : Control
{
    SharedFunctionality mySharedFunctionality = new SharedFunctionality();

    public void OnLoad()
    {
        mySharedFunctionality.ImportantToCallThisOnLoad();
    }
}


Instead of having the Forms & UserControls inherit from a base class can you encapsulate the logic inside of a self contained object so that each form will new up? Then you can limit in the base class just the instantion and interaction with this object which hopefuly is minimal so having it done twice isn't a big deal.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜