Hi Lama,
I have created sample that full-fill your requirement.
For Windows Application
You can do it in two ways.
Code
C#
private Button enterBut = new Button();
private void enterButClick(System.Object sender, System.EventArgs e)
{
Control ctl = (Control)lastObj;
this.SelectNextControl(ctl, true, true, true, true);
wasClick = false;
}
private void Form1_Load(System.Object sender, System.EventArgs e)
{
enterBut.Click += enterButClick;
this.AcceptButton = enterBut;
}
object lastObj = new object();
private void EnterTXT(object sender, System.EventArgs e)
{
lastObj = sender;
}
bool wasClick;
private void Buttons_Click(System.Object sender, System.EventArgs e)
{
if (!wasClick)
enterBut.PerformClick();
}
private void Buttons_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
wasClick = true;
}
Or
private void TextBox1_KeyDown(System.Object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter) {
SendKeys.Send("{tab}");
e.SuppressKeyPress = true;
}
}
VB .Net
Private WithEvents enterBut As New Button
Private Sub enterButClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim ctl As Control = DirectCast(lastObj, Control)
Me.SelectNextControl(ctl, True, True, True, True)
wasClick = False
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
AddHandler enterBut.Click, AddressOf enterButClick
Me.AcceptButton = enterBut
End Sub
Dim lastObj As New Object
Private Sub EnterTXT(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter, TextBox2.Enter, TextBox3.Enter, Button1.Enter
lastObj = sender
End Sub
Dim wasClick As Boolean
Private Sub Buttons_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not wasClick Then enterBut.PerformClick()
End Sub
Private Sub Buttons_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
wasClick = True
End Sub
Or
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown, TextBox2.KeyDown, TextBox3.KeyDown
If e.KeyCode = Keys.Enter Then
SendKeys.Send("{tab}")
e.SuppressKeyPress = True
End If
End Sub
Screenshot