dotnetmonitor.com

 
Index
Previous
Next

 

/***********************************************************************

* Setup (using the Visual Studio Form designer):

*

* Use the Same Form as in the sample above but change the CurrentTime

* type to provide Change notification for the Now property. This sample

* uses the PropertyChanged pattern. The label Text value will correctly

* update in this sample.

***********************************************************************/

 

public class CurrentTime

{

System.Windows.Forms.Timer _timer;

 

public CurrentTime()

{

/***************************************************************

* Use a timer to keep track of the current timer

***************************************************************/

_timer = new System.Windows.Forms.Timer();

 

/***************************************************************

* Update the time every second

***************************************************************/

 

_timer.Interval = 1000;

_timer.Tick += delegate { this.Now = DateTime.Now; };

_timer.Start();

}

 

/*******************************************************************

* Use a timer to keep track of the current time

*******************************************************************/

 

private DateTime _now = DateTime.Now;

 

/*******************************************************************

* Property Change Notification fired bound UI elements will

* update when this property changed

*

* This uses the PropertyChanged pattern

*******************************************************************/

 

public DateTime Now

{

get { return _now; }

private set

{

if (_now != value)

{

_now = value;

OnNowChanged(EventArgs.Empty);

}

}

}

 

/*******************************************************************

* Provide a PropertyChanged event

*******************************************************************/

 

public event EventHandler NowChanged;

 

protected virtual void OnNowChanged(EventArgs e)

{

if (null != NowChanged)

{

NowChanged(this, e);

}

}

}

Simple Binding
Complex Binding
Using Simple Binding with a List
Sample: Simple Binding to a List (VS 2005) (VS Project: DataBinding Intro)
Type Conversion
Formatting