samedi 22 janvier 2022

Decorator pattern on a panel

I am trying to make a winform Panel that will be scrollable with a decorator design pattern. But I dont understand how I can use it with an interface because than I am losing all of the panel properties like size,location etc.

when I initialize the component I declare him like this:

IPanel scrollablePanel= new VScrollablePanell(new CorePanel())

I am probably doing something wrong but I cant figure it out, hope you can help me out

public interface IPanel
    {
        void Operation();
    }

    public class CorePanel : Panel,IPanel
    {
        public void Operation() { }

    }
    public class PanelDecorator :IPanel
    {
        protected IPanel m_Decorated;
        public PanelDecorator(IPanel i_Decorated)
        { m_Decorated = i_Decorated; }
        public virtual void Operation()
        { m_Decorated.Operation(); }

    }
    public class VScrollPanel : PanelDecorator
    {
        public VScrollPanel(IPanel i_Decorated) :
        base(i_Decorated)
        { }
        public override void Operation()
        {
            Scroll();
        }
        private void Scroll()
        {
}

Aucun commentaire:

Enregistrer un commentaire