我想知道我使用“退格”的时间有多少在VB.NET上 [英] I want to know how many time I using "backspace" on VB.NET
本文介绍了我想知道我使用“退格”的时间有多少在VB.NET上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这个richtextbox中,我想知道在键盘上使用Backspace的次数。到目前为止我已经使用了这段代码,但是出了点问题。这是场景,当按Enter键时,消息框将显示使用Backspace的时间。请帮帮我..
我尝试过:
In this richtextbox I want to know how many time using "Backspace" on keyboard. So far I already using this code, but something wrong. this is the scenario, When pressing Enter, message box will show how many time using Backspace. Please help me..
What I have tried:
Public Class Form1
Private Sub RichTextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles RichTextBox1.KeyDown
Dim count As Integer
If (e.KeyCode = Keys.Back) Then
count = count + 1
ElseIf (e.KeyCode = Keys.Enter) Then
MessageBox.Show(count)
End If
End Sub
End Class
推荐答案
count
是一个局部变量,它只在方法退出时存在,并在每次新事件调用该方法时重新创建并重新初始化。
你需要通过在方法之外移动它来使它成为你的班级声明的艺术:
count
is a local variable, it exists only until the method exits and is recreated and reinitialised each time the method is called by a new event.
You need to make it art of your class declaration by moving it outside the method:
Public Class Form1
Private count As Integer = 0
Private Sub RichTextBox1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
If (e.KeyCode = Keys.Back) Then
count = count + 1
ElseIf (e.KeyCode = Keys.Enter) Then
MessageBox.Show(count)
End If
End Sub
End Class
这篇关于我想知道我使用“退格”的时间有多少在VB.NET上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文