toolStripTextBox中的Keypress事件 [英] Keypress Event in toolStripTextBox
本文介绍了toolStripTextBox中的Keypress事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段代码:
I have this code:
private void toolStripTextBox7_KeyPress(object sender, KeyPressEventArgs e)
{
if (toolStripTextBox7.Text != "one" && toolStripTextBox7.Text != "two")
{
pictureBox21.BringToFront();
}
else
{
pictureBox20.BringToFront();
}
}
当用户插入一个或两个时我希望它改变图片,但这不是做到这一点。在这种情况下,我必须写入一个或两个,然后再单击该框中的一次以刷新它,然后它可以工作。如何解决这个问题?
I want it to change the picture that moment, when user inserts "one" or "two", but this does not do it. In this case i have to write in "one" or "two" and click one more time in that box to refresh it, then it works. How to fix this?
推荐答案
这不是问题 - 它与事情发生的顺序有关:KeyPress发生之前 文本按设计更改,因此如果您不想要非数字值,则可以删除按键。
尝试将代码移动到TextChanged事件中,这会在文本更改后发生。
This isn''t a problem - it has to do with the order in which things happen: KeyPress occurs before the text is changed by design, so you can remove key presses if you don''t want non-numeric values for example.
Try moving your code into the TextChanged event instead, which occurs after the text is changed.
这篇关于toolStripTextBox中的Keypress事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文