如何访问在的WinForms设计师继承控制 [英] How to access inherited controls in the winforms designer

查看:157
本文介绍了如何访问在的WinForms设计师继承控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一些控制,所有必须共享相同的外观和一些常见的行为,虽然他们都是为了别样的投入。于是我做了一个BaseClass的从用户控件继承,和我所有的控制从BaseClass的继承。



不过,如果我添加控件在设计BaseClass的,如一个TableLayoutPanel,当我设计的继承类,我不能访问它们。我看到了TableLayoutPanel中,但即使他是受保护,我不能对其进行修改或将控制在它通过设计师。我没有麻烦通过代码accesing,但我不想失去使用设计的能力。



现在,我只是删除了所有的控制从BaseClass的补充的布局和所有的通用控件中的每个继承类的,然后用引用操纵它们里面的BaseClass。但是,这并不满足我。 ?有没有一种方法,使具有继承保护成员的控制设计工作。



环境:C#,.NET 3.5,Visual Studio 2008中



编辑回答SLaks的建议。我试着设置属性,虽然我不习惯使用它们似乎并没有工作。这里是我试过的代码:

 公共部分类的UserControl1:用户控件
{
公众的UserControl1()
{
的InitializeComponent();
}

公共TableLayoutPanel中TableLayoutPanel1
{
{返回tableLayoutPanel1;}
集合{tableLayoutPanel1 =值;}
}
}

公共部分类UserControl2:的UserControl1
{
公共UserControl2()
{
的InitializeComponent();
}
}


解决方案

当您尝试从与设计师的TableLayoutPanel中继承的控制访问基本控件声明,您是在WinForms的被称为视觉继承使用功能。



不幸的是TableLayoutPanel中不支持可视化继承:
http://msdn.microsoft.com/en-us/library/ms171689%28VS.80%29.aspx



这就是为什么出现TableLayoutPanel中挡在继承的控制。


I'm making some controls which all have to share the same look and some common behavior, although they are meant for different kind of inputs. So I made a BaseClass which inherit from UserControl, and all my controls inherit from BaseClass.

However, if i add controls for BaseClass in the designer, such as a TableLayoutPanel, i can't access them when I'm designing the inherited classes. I see the TableLayoutPanel, but even though he is "protected", i can't modify it or put controls in it through the designer. I've no trouble accesing it by code, but i don't want to lose the ability to use the designer.

Right now, i simply removed all controls from BaseClass, added the layout and all the common controls in each of the inherited class, then use references to manipulate them inside BaseClass. But that doesn't satisfy me at all. Is there a way to make the designer work with inherited protected member controls ?

Environment : C#, .NET 3.5, Visual Studio 2008

EDIT to answer SLaks's suggestion. I tried setting a property, and although I'm not used to use them it doesn't seem to work. Here is the code i tried :

    public partial class UserControl1 : UserControl
    {
            public UserControl1()
            {
                    InitializeComponent();
            }

            public TableLayoutPanel TableLayoutPanel1
            {
                    get { return tableLayoutPanel1;}
                    set { tableLayoutPanel1 = value;}
            }
    }

    public partial class UserControl2 : UserControl1
    {
            public UserControl2()
            {
                    InitializeComponent();
            }
    }

解决方案

When you try to access from the inherited control with the designer to the TableLayoutPanel declared in the base control, you're using a feature in WinForms called "Visual Inheritance".

Unfortunately TableLayoutPanel doesn't support visual inheritance: http://msdn.microsoft.com/en-us/library/ms171689%28VS.80%29.aspx

That's why the TableLayoutPanel appears blocked in the inherited controls.

这篇关于如何访问在的WinForms设计师继承控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆