C# TabPage 继承

发布于 2024-10-08 18:49:29 字数 159 浏览 5 评论 0原文

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

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

I have two classes. First class has TabPage control. I want to change layout of TabPage in Child class(Class B). For example how to add simple button to tabPage control in Child class?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

提笔落墨 2024-10-15 18:49:29

将 TabPage 更改为公开

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

    }

Change the TabPage to public

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

    }
情深缘浅 2024-10-15 18:49:29

首先你需要将A类中的TabPage设为public,然后在你的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,请将其设为公共,否则将受到保护。

受保护

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

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文