我新建了一个自定义控件,里面有个textbox,现在想把这个textbox的text属性取到的值直接赋值给自定义控件,但是自定义控件没有text属性,求解?

解决方案 »

  1.   


    private string _text;
    public string Text
    {
    get{return this._text;}
    set{this._text = value;}
    }访问
    usercontrol1.Text = "sss";
      

  2.   


    public class MyUserControl {
        public string Text{
            get{ return textBox1.Text;}
            set{ textBox1.Text = value;}
        }

      

  3.   

    public string Text
    {
    get{return testBox1.Text}
    }
      

  4.   

    int step = 0;
                UCTextInput[] ll = new UCTextInput[100];
                for (var i = 0; i < 15; i++)
                {
                    ll[i] = new UCTextInput();
                    ll[i].Text = "sss";
                    ll[i].Left = 0;
                    ll[i].Top = 0 + step;
                    step = step + 50;
                    ll[i].Name = "UCinput" + i.ToString();
                    this.panel1.Controls.Add(ll[i]);
                }//自定义控件中
    public partial class UCTextInput : UserControl 
        {
            private string _text;
            public string Text
            {
                get { return this._text; }
                set { this._text = value; }
            }        public UCTextInput()
            {
                InitializeComponent();
                this.UClbl.Text = this.Name;
                this.Text = this.UCtxb.Text;
            }
    }
    大侠们看看这么写有米有问题啊?为什么所有自定义控件的中label的值都是UCTextInput(也就是自定义控件的Name值),应该是UCinput0.。。才对啊
      

  5.   

    set { this._text = value; }
    这个里面应该对lable赋值        public string Text
            {
                get { return this._text; }
                set { this._text = value;  this.UClbl.Text =value;}
            }
     
      

  6.   

    public string Text
            {
                get { return this._text; }
                set { this._text = value; value = this.UCtxb.Text; }
            }
    那我自定义控件中的text值是这么获取的?
      

  7.   

    貌似不行哇,是不是在初始化自定义控件的时候需要把里面textbox的text值先赋给自定义控件的text才行呀?