Text property in a UserControl in C#

前端 未结 3 1213
既然无缘
既然无缘 2020-11-30 05:46

I have a control with a inner TextBox. I want to make a direct relationship between the Text property of the UserControl and the Text property of the TextBox. The first thin

相关标签:
3条回答
  • 2020-11-30 06:16

    Reflector is a crucial tool for a .NET developer. It is immediately obvious what you need to do when you use it to look at the UserControl.Text property:

    [Bindable(false), EditorBrowsable(EditorBrowsableState.Never), Browsable(false),
     DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public override string Text
    {
        get
        {
            return base.Text;
        }
        set
        {
            base.Text = value;
        }
    }
    

    Ho showed you what you need to do to cancel these attributes, too bad he didn't show you how he found out. Reflector is was free, download it from redgate.com or check the alternatives here : Something Better than .NET Reflector?

    0 讨论(0)
  • 2020-11-30 06:20

    For serialization within the InitializeComponent(), all you need is the DesignerSerializationVisibilityAttribute:

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    
    0 讨论(0)
  • 2020-11-30 06:35

    You need more attributes:

    [EditorBrowsable(EditorBrowsableState.Always)]
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    [Bindable(true)]
    public override string Text { get; set; }
    
    0 讨论(0)
提交回复
热议问题