在我想知道的 CheckedChanged 事件中,哪个操作触发了此更改,要么是用户显式单击了复选框,要么是从数据绑定更新的。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Source = new ValueSource();
this.checkBox1.DataBindings.Add(new Binding("Checked", Source, "State", false, DataSourceUpdateMode.OnPropertyChanged));
this.checkBox1.CheckedChanged += new EventHandler(checkBox1_CheckedChanged);
}
void checkBox1_CheckedChanged(object sender, EventArgs e)
{
// databinding changed the value.
MessageBox.Show("Value changed from data binding");
// user checked the check box using mouse.
MessageBox.Show("Value changed due to use action");
}
public ValueSource Source { get; set; }
}
public class ValueSource
{
private bool state = true;
public bool State
{
get { return state; }
set { state = value; }
}
}