这是一个测试框架,用于显示我在做什么:
(使用控件的默认名称)
public partial class Form1 : Form
{
private List<bool> boolList = new List<bool>();
BindingSource bs = new BindingSource();
public Form1()
{
InitializeComponent();
boolList.Add(false);
bs.DataSource = boolList;
checkBox1.DataBindings.Add("Checked", bs, "");
this.button1.Click += new System.EventHandler(this.button1_Click);
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
}
bool updating = false;
private void button1_Click(object sender, EventArgs e)
{
updating = true;
boolList[0] = true;
bs.ResetBindings(false);
Application.DoEvents();
updating = false;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (!updating)
MessageBox.Show("CheckChanged fired outside …Run Code Online (Sandbox Code Playgroud)