Search code examples
user-controlscompact-framework

Compact Framework 3.5 Update Usercontrol With Main Form Variable Data


This seems like it should be simple, however, I cannot find an example through searching... How do I update a label on a usercontrol using variables from its parent form?

I am building a compact framework 3.5 application.

Thanks for any and all assistance!!!


Solution

  • You can create a public property on the user control, and you update your label from there, for example:

    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }
    
        public string LabelText
        {
            get
            {
                return label1.Text;
            }
            set
            {
                label1.Text = value;
            }
        }
    }
    

    You can also return the label itself, although some people may say that would break encapsulation on your design.