Windows Develop Bookmark and Share   
 index > Windows Forms General > textboxes, comboboxes, ... return key and tab key
 

textboxes, comboboxes, ... return key and tab key

In vb.net textboxes (and other controltypes, I suppose), pressing Return doesn't cause the focus to be passed to the next control (and, therefore, the events related to validation and the like to be fired. On the other hand, pressing Tab key works that way, so.... is there any way (configuration, properties,...) that would make textboxes react to Enter the same than to Tab???

thanks
amc  Saturday, October 15, 2005 9:01 PM
You can add an event handler for the KeyPress event of each textbox. Then use this code:



private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == '\r')
    {
        ProcessTabKey(
true);
        e.Handled =
true;
    }
}


 
Daniel Rieck  Sunday, October 16, 2005 11:56 AM
well, thanks, but this forces to write an event handler to EACH textbox. So, if there is no other wiser method, then maybe I should derive a class from textbox (something like TextBoxAcceptingReturn class), so I need to write the event once....

thanks
amc  Sunday, October 16, 2005 7:42 PM
If you want something specific to happen on every TextBox that you add to your form, you should consider deriving your own class from the TextBox control class. Deriving your own class IS the wiser choice. ;)
Anders Tornblad  Sunday, October 16, 2005 8:12 PM

You can use google to search for other answers

Custom Search

More Threads

• Window modality- using .ShowDialog doesn't work! Plss help
• Stacked column chart
• insert date into oracle database
• Handle pop up windows in WebBrowser control
• Mixing Legacy C and Windows Forms
• MenuItem doesn´t fire Click event
• GDI+ borderless/transparent form bugs... No context menu in taskbar. Maximizes on top of taskbar.
• Control (Button etc) Focus Rectangle and Selection
• OnPaint called very frequently on UserControl
• Creating Undo, Cut, Copy, Paste, Find and Find Next toolstrip controls???