值不在textbox1_keypress上播种 [英] Value not sow on textbox1_keypress

查看:68
本文介绍了值不在textbox1_keypress上播种的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1-当我在

TextBox1_KeyPress

事件值未在TextBox1中显示



2 - 当我在

event value not be showing in TextBox1

2- When i enter "1" in

TextBox1_TextChanged

在TextBox中显示的事件值



我试过的:



event value showing in TextBox

What I have tried:

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
      Array(0) = TextBox1.Text ' Showing
  End Sub

  Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
      Array(0)= TextBox1.Text 'Not showing
  End Sub

推荐答案

这是因为KeyPress事件发生在文本更改之前。如果你考虑一下,这是唯一可行的方法:他按下的键可能不是文本键,可能是TAB,ENTER,光标移动,功能键,......或者你可能试图防止字母键在仅数字文本框中工作说。

KeyPressEventArgs具有KeyChar属性,它告诉您按下了什么键,以及Handled属性,以防止密钥继续进行 - 如果它; s设置为true,则它停在那里并且正常键处理不会发生。
That's because the KeyPress event happens before the text is changed. If you think about it, that's the only way it could work: the key that he pressed might not be a text key, it could be TAB, ENTER, a cursor movement, a Function key, ... or you could be trying to prevent alphabetic keys from working in a numeric only textbox say.
The KeyPressEventArgs has the KeyChar property which tells you what key was pressed, and the Handled property to allow you to prevent the key from going any further - if it;s set to true, then it stops there and the "normal" key processing doesn't happen.


这篇关于值不在textbox1_keypress上播种的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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