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”上有错误吗?
答案 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