Utilizzare l'enter insieme al tab sui controlli per cambiare il controllo attivo

Per intercettare l'enter sui controlli è utilizzato l'evento keypress:

C#

this.textBox2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextBoxKeyPress);
void TextBoxKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
   
if (((int)e.KeyChar).Equals((int)Keys.Enter))
      
this.SelectNextControl((Control)sender, true, true, true, true);
}

VB.NET

AddHandler Me.textBox2.KeyPress, AddressOf Me.TextBoxKeyPress
Private Sub TextBoxKeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) 
    
If (DirectCast(e.KeyChar, Integer)).Equals(DirectCast(Keys.Enter, Integer)) Then
        Me
.SelectNextControl(DirectCast(sender, Control), True, True, True, True)
   
End If
End Sub

Print | posted on venerdì 11 agosto 2006 12:28

Feedback

# re: Utilizzare l'enter insieme al tab sui controlli per cambiare il controllo attivo

Left by hector at 28/03/2007 20:25
Gravatar ottimo

Your comment:





 
Please add 1 and 2 and type the answer here:

Copyright © Luciano Bastianello

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski