Panel & keyboard focus

  • Thread starter Thread starter Mikhail Fedosov
  • Start date Start date
M

Mikhail Fedosov

I have a panel and some of my controls on it (each control is derived from
Control, not from UserControl). I need to delete the selected control by
pressing the Del key. How it can be done? Panel does not process any
keyboard events. Also I don't want to delete any controls when focus is on
the other controls of the form.

So the scenario is something like this:
1. User clicks on some of my controls (panel receives focus)
2. User press Del key (control removes from panel)
3. User press Tab key (the focus is received by another control of the form,
but not a control of the panel)
4. User press Del key (nothing happens)

So the main question is how can I monitor focus state of the panel and
process the keygboard input?

Thank you very much.
 
Is it possible to think about this problem from another angle? Could
you have the control itself handle the keyboard event when it has
focus, or would that end up bastardizing the purpose of the control?

In other words, could you change your own controls to know "A DEL
keypress means that I should delete myself from my enclosing panel
when I am on the panel that allows deletions"? Rather than having the
panel know to delete the control, have the control know to delete
itself when it is in that panel and it receives a DEL keypress?

Of course, this may not be reasonable if the controls are generic use
and this is simply a special situation that you don't want to code
into the controls. Just an idea.
 
Thank you. It works!

I just wonder why Panel control can't receive keyboard input.
 
Back
Top