ผมอยากให้เวลากด enter แล้ว cursor เปลี่ยนไปอีก textbox หนึ่ง ทำไงครับ รบกวนหน่อยครับ
Tag : .NET, Ms Access, VS 2008 (.NET 3.x), VS 2010 (.NET 4.x)
Date :
2011-05-19 15:07:33
By :
nnn
View :
9103
Reply :
9
No. 1
Guest
Code (VB.NET)
If e.KeyChar = Chr(13) Then
Textbox.Focus()
End If
ใช้ event keypress นะคับ
Date :
2011-05-19 15:16:42
By :
xx
No. 2
Guest
Code (VB.NET)
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(13) Then
TextBox1.Focus()
End If
End Sub
Module Module1
Private Sub TextBox1_KeyPress(ByVal sender As Object)
Dim e As System.Windows.Forms.KeyPressEventArgs
If e.KeyChar = Chr(13) Then
DirectCast(sender, TextBox).Focus()
End If
End Sub
End Module
มันขึ้น Warning 1 Variable 'e' is used before it has been assigned a value. A null reference exception could result at runtime.
ทำไงครับ
Module Module1
Public Sub TextBox_KeyPress( ByVal e As System.Windows.Forms.KeyPressEventArgs, txt_2 As TextBox)
If e.KeyChar = Chr(13) Then
txt_2.Focus()
End If
End Sub
End Module
การเรียกใช้ Code (C#)
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
TextBox_KeyPress(e,TextBox2)
End Sub