Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

user control - public property

Been away from Windows Form Controls dev for a while.

I have a control that displays the date and time in a label.

I want to create a property that is visible in the visual studio "Properties" window, such that I can grab the current contents of the label any time I want to.

I think attributes are used, but I don't remember how to do it.

Thanks, and please include small 'hello world" sample C# code for me.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Knowlton

ASKER

Thanks!
My interim solution:

namespace DateTimeControl
{
    public partial class UserControlDateTime: UserControl
    {
        public UserControlDateTime()
        {
            InitializeComponent();
        }


        [Description("DateTime displayed by the label"), Category("Data")]
        public string LabelDateTimeText
        {
            get { return labelDateTime.Text; }            
        }
        private void timerTick_Tick(object sender, EventArgs e)
        {
            DateTime dt = new DateTime();
            dt = DateTime.Now;
            labelDateTime.Text = dt.ToLongDateString() + " " + dt.ToLongTimeString();
        }

      
    }

Open in new window