Hi Yatin,
In response to your comment on my previous answer, I am not aware of any property that will do this.
The only way that I know is to iterate over the controls collection of the
Form
and if the control is the type that requires this functionality, add your handler to its
KeyPress
or
KeyDown
event. Something like this:
void frm1_Load(....)
{
IterateThroughChildren(this);
}
void IterateThroughChildren(Control parent)
{
foreach (Control c in parent.Controls)
{
if (c is TextBox || c is ComboBox) <============ See below
{
c.KeyDown += MyKeyDownHandler;
}
if (c.Controls.Count > 0)
{
IterateThroughChildren(c);
}
}
}
void MyKeyDownHandler(....)
{
if (e.KeyCode == Keys.Enter)
{
((Control)sender).SelectNextControl(....);
}
}
The test for
TextBox
or
ComboBox
is there to avoid the event handler being applied to things like
Panels
devise your own test to suit your circumstances.
One other thing to consider is what to do with
Controls
that might expect the enter key (Multi-line TextBoxes or ListBoxes for example). These will have to be handled differently, maybe test for Ctrl-Enter for those.
Good luck! :)