0

我有两节课。第一类有 TabPage 控件。我想更改子类(B 类)中 TabPage 的布局。例如如何在 Child 类的 tabPage 控件中添加简单的按钮?

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

2 回答 2

3

将 TabPage 更改为 public

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

    }
于 2010-12-22T12:27:28.723 回答
1

首先你需要让A类中的TabPage是公开的,然后在你的控件集合中添加你想要添加的TabPage控件;在此示例中,我添加了一个按钮,TabPage您可以类似地添加更多控件。

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);
}

这实际上取决于您的情况,如果您也想从基类访问 TabPage,请将其设为 public 否则受保护。

对于受保护的

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;
}
于 2010-12-22T12:41:29.750 回答