csharp
List<int> integerList = new List<int> { 0 };
BindingSource bs = new BindingSource();
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
bs.DataSource = integerList;
label1.DataBindings.Add("Text", bs, "");
}
private void button1_Click(object sender, EventArgs e) {
integerList[0]++;
bs.ResetBindings(false);
}
上述代码效果为点击Button
,Lable
的值++