【发布时间】:2010-12-11 07:01:59
【问题描述】:
我有一个这样定义的用户控件:
public partial class FooControl : UserControl
{
private System.Windows.Forms.GroupBox groupBox1;
...
我想让 groupBox1.Text 直接从设计器访问,所以我选择了明显的解决方案并在我的 FooControl 中创建了以下属性:
[CategoryAttribute("Appearance"), DescriptionAttribute("The text associated with this control.")]
public string Text
{
get { return groupBox1.Text; }
set { groupBox1.Text = value;}
}
这不起作用,因为 Text 已经在我的超类中定义了(实际上,由于 browserable=false 属性,它有点不知所云,但我最终找到了它):
public class UserControl : ContainerControl
{
[Bindable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override string Text { get; set; }
一个简单的解决方法是使用“Text2”而不是“Text”作为属性名称,在这种情况下一切正常。
但是,如果我使用 override 或 new,我的代码会编译(并且可以工作),但我的 Text 属性在设计器中不可见。
这种行为的原因是什么?是否有解决方法(除了使用其他属性名称)?
【问题讨论】:
标签: .net visual-studio winforms inheritance attributes