are you aware that key event are only send to focused control ? and that
there is only one focused control ?
once the form has put the focus somewhere, it won't receive any more key
event
moreover label.KeyEvent doesn't work
--
ihookdb
Get your data mobile
http://www.ihookdb.com
MalawiBwana said:
I have a form with a label on top and 2 panels (panel1 and panel2). Panel
2 is within panel1 and panel1 is placed on the form just below the label. On
panel2, I have a series of labels and combo boxes, side by side...something
like this:
label 1 comboBox1
label 2 comboBox2
. .
. .
These labels and comboBoxes are defined as arrays and are generated at runtime.
I am trying to add a KeyDown event to this form...basically when the user
presses the right key, the focus goes to the next control. And when the
focus is on the combo box, the down key should scroll through the contents.
The right key should then take the focus out of the combo box and go to the
next label.
The problem I am having is that the KeyDown event is captured only
once...after that the program doesn't listen to any KeyEvents. Is this
because I have a panel on the form and the focus is not on the panel? How
can I fix this?
Any help is appreciated. Thanks!
CODE SNIPPET:
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.OptionsDialog_KeyDown);
this.panel1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.OptionsDialog_KeyDown);
this.panel1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.OptionsDialog_KeyDown);
private void OptionsDialog_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
switch(e.KeyCode)
{
case Keys.Return:
break;
case Keys.Down:
break;
case Keys.Up:
break;
case Keys.Left:
break;
case Keys.Right:
if (index == 0)
{
this.labelSelections.Focus();
index++;
labelIndex = 0;
comboIndex = 0;
}
else
{
if (index % 2 != 0) // its a label
{
this.label[labelIndex].Focus();
labelIndex++;
index++;
}
else
{
this.comboBox[comboIndex].Focus();
comboIndex++;
index++;
}
}
break;
}
}