locked
trackbar databinding RRS feed

  • Question

  • I need to bind a trackbar value with an integer that I have, which is constantly changing. How can I do that?
    Tuesday, July 21, 2009 1:44 AM

Answers

  • Hi aherlambang,

    You need to wrap it into a class in order to use DataBinding. That class should implement INotifyPropertyChanged interface. Here is the example.
        public class MyInteger : INotifyPropertyChanged
        {
            public event PropertyChangedEventHandler PropertyChanged;
            private int intValue;
            public int IntValue
            {
                get { return intValue; }
                set
                {
                    intValue = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("IntValue"));
                }
            }

            public MyInteger()
            {
                PropertyChanged = new PropertyChangedEventHandler(OnPropertyChanged);
                intValue = 0;
            }

            protected void OnPropertyChanged(object send, PropertyChangedEventArgs e)
            {
            }
        }

    To use this class in DataBinding.
    MyInteger myInt = new MyInteger();
    myInt.IntValue = 1;
    trackBar1.DataBindings.Add("Value", myInt, "IntValue");

    Sincerely,
    Kira Qian
    Please mark the replies as answers if they help and unmark if they don't.
    • Marked as answer by Kira Qian Monday, July 27, 2009 6:29 AM
    Wednesday, July 22, 2009 7:35 AM