KeyChar不是System.EventArgs错误的成员

时间:2013-11-20 20:24:32

标签: vb.net winforms

Imports System.IO

Public Class Form1
  Private Sub txtFileName_TextChanged(sender As Object, e As EventArgs) Handles txtFileName.TextChanged
    If e.KeyChar = ChrW(Keys.Enter) Then
      Dim FileNameTyped As New FileInfo(Me.txtFileName.Text)
      If FileNameTyped.Exists Then
        Call ShowFileContents(Me.txtFileName.Text)
      Else
        MessageBox.Show(" File does not exist ")
      End If
    End If
  End Sub
End Class

很抱歉所有的代码但是我迷路了你可以告诉我为什么我在“e.KeyChar”上有错误吗?

1 个答案:

答案 0 :(得分:2)

我会使用KeyDown事件:

Private Sub txtFileName_KeyDown(sender As Object, e As KeyEventArgs) _
                                Handles txtFileName.KeyDown
  If e.KeyCode = Keys.Enter Then
    ' // do stuff
  End If
End Sub