1
我有兩個文本框,我想計算每個文本框時,其他changed.but我的程序陷入一個循環。如何防止相關事件的發生?
private bool suspendEvents = false;
private void txtYourPercent_ValueChanged(object sender, EventArgs e)
{
if (suspendEvents)
return;
suspendEvents = true;
txtMyPercent.value = 100 - txtYourPercent.value;
suspendEvents = false;
}
private void txtMyPercent_ValueChanged(object sender, EventArgs e)
{
if (suspendEvents)
return;
suspendEvents = true;
txtYourPercent.value = 100 - txtMyPercent.value;
suspendEvents = false;
}
這是我way.This方法disgusting.Any更好的解決辦法? (「WinForms」)
如果沒有其他解決方案,請告訴我刪除此問題並使用我的(嘟嘟聲)解決方案。
**嘿bro.It將下降Loop.I認爲它不工作。 ** – WishToBePro 2011-04-10 14:52:50
@WishToBePro,它在我測試它時工作。 – 2011-04-10 14:56:43
@WishToBePro:然後發佈您的所有代碼。 – 2011-04-10 15:25:09