日期:2014-05-17 浏览次数:21006 次
public partial class Form1 : Form
{
public class Test : System.ComponentModel.INotifyPropertyChanged
{
private int m_Count = 0;
public int Count
{
get { return m_Count; }
set
{
m_Count = value;
NotifyPropertyChanged("Count");
}
}
public void Begin()
{
Thread thread = new Thread(Counter);
thread.Start();
}
private void Counter()
{
for (int i = 0; i < 1000; i++)
{
Count = i;
System.Threading.Thread.Sleep(100);
}
}
public void NotifyPropertyChanged(string info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
#region INotifyPropertyChanged 成员
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
public Form1()
{
InitializeComponent();
Binding binding = new Binding("Text", t, "Count");
label1.DataBindings.Add(binding);
}
Test t = new Test();
private void button1_Click(object sender, EventArgs e)
{
t.Begin();
}
}