如何使用键在文本框 1 中显示文本框 2 值
本文关键字:文本 显示 何使用 | 更新日期: 2023-09-27 18:31:17
我有2个文本框(textbox 1和textbox 2);textbox1有数字值,如$1,000。现在,当我在文本框 2 中时,如果我点击诸如 (= 或 + 或向上翻页或向下翻页等)之类的击键,文本框 1 值应该出现在文本框 2 中。
这背后的原因是使客户能够提高处理/填充数据的速度。
我不知道
我是否理解你需要什么,无论如何试试这个:
private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.PageDown ||
e.KeyCode == Keys.PageUp ||
e.KeyCode == Keys.Oemplus ||
e.KeyCode == Keys.Add ||
(e.KeyCode == Keys.D0 && e.Shift))
{
textBox2.Text = textBox1.Text;
e.Handled = true;
e.SuppressKeyPress = true;
}
}
如何使用如下函数在 textbox2 上添加一个 keyPress 事件:
private void textbox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '+')
{
textbox2.Text = textbox1.Text;
}
}
你可以试试这个:
protected void textbox2_TextChanged(object sender, EventArgs e)
{
if(textbox2.Text=="+"||textbox2.Text=="=")
textbox2.Text=textbox1.Text;
}