C#同时更新两个文本框? [英] C# update two text boxes at the same time?

查看:43
本文介绍了C#同时更新两个文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个文本框,一个保存二进制数据,另一个是 ASCII 等价的.如果用户假设更改其中任何一个,我将如何同时更新另一个文本框,而无需按下按钮?

Let's say I have two text boxes, one holds binary data and the other it's ASCII equivalent. If the user let's say changes either one of them, how would i have the other text box updated at the same time, without having to press a button?

推荐答案

你必须防止 无限循环 (asciiTextBox 改变 binaryTextBox.Text 改变 asciiTextBox.Text 等),你可以实现类似的东西:

You have to prevent an infinite loop (asciiTextBox changes binaryTextBox.Text which changes asciiTextBox.Text etc.), and you can implement something like that:

private void asciiTextBox_TextChanged(object sender, EventArgs e) {
  binaryTextBox.TextChanged -= binaryTextBox_TextChanged;

  try {
    binaryTextBox.Text = BinaryText(asciiTextBox.Text);
  }
  finally {
    binaryTextBox.TextChanged += binaryTextBox_TextChanged; 
  }
}

private void binaryTextBox_TextChanged(object sender, EventArgs e) {
  asciiTextBox.TextChanged -= asciiTextBox_TextChanged;

  try {
    asciiTextBox.Text = AsciiText(binaryTextBox.Text);
  }
  finally {
    asciiTextBox.TextChanged += asciiTextBox_TextChanged;
  }
}

这篇关于C#同时更新两个文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆