开发者

C# TabPage inheritance

I have two classes. First class has TabPage control. I want to change layout of TabPage in Child class(Class B). For examp开发者_如何学Gole how to add simple button to tabPage control in Child class?

Class A
{
   TabPage a;
}
Class B : Class A
{
}


Change the TabPage to public

    class A
    {
        public TabPage a;
    } 
    class B : A
    {

    }


First you need to have TabPage in Class A to be public, then add the controls you want to add in your TabPage control collection; in this example i have added a button to the TabPage you can add many more controls similarly.

class A
{
    public TabPage a;
} 
class B : A
{
        //Create a control to add and set its properties
        Button btn = new Button();
        btn.Location = new Point(20, 20);
        btn.Size = new Size(120, 25);
        btn.Text = "My new Button";
        //Add the control to the Tabpage.
        a.Controls.Add(btn);
}

It really depends upon your situation, if you want to have TabPage accessible from base class too, make it public otherwise protected.

For protected

class A
{
    //Visible only to Inheriting class;
    protected TabPage a;
} 
class B : A
{
        //Create a control to add and set its properties
        Button btn = new Button();
        btn.Location = new Point(20, 20);
        btn.Size = new Size(120, 25);
        btn.Text = "My new Button";
        //Add the control to the Tabpage.
        a.Controls.Add(btn);
        //This will be visible to everybody
        public TabPage b= a;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜