3
votes

When one works in WinForms designer, you can click on a child control to select it. When you then hit the Esc key, the selection moves up to the parent control. If you press Esc key again, the next parent control up gets selected, until finally one reaches the form itself.

I have a user control with various child controls and have configured it for design-time support. When I click on a permitted child control it gets selected. When I press Esc key, however nothing happens. How, do I trap the Esc key at design time and move selection up to the parent control?

1
I suppose you can't, because Microsoft VS is a program itself, and it can control its component at design time, while in your case, you make a control at design time then it's impossible. Try to make a new design program for your demand.Thinhbk
Not sure about that one, but have you tried the KeyPress event to Focus() some other object? Probably the parent control KeyPress event would do the trick with Form1.Focus();. You just need to activate the KeyPreview property on Form1 for it to work properly. I'm not sure neither am i near VS to test it, that's why i didn't post as answer.Fernando Silva

1 Answers

0
votes

I'm not certain this will work, but you could try something along the lines of:

Register the form with a keypress event:

this.KeyPress += new KeyPressEventHandler(frm_Main_KeyPress);

If the escape key is hit, get the activecontrol's parent and select it.

void tc_Main_KeyPress(object sender, KeyPressEventArgs e)
{
    if e.KeyChar = (char)27{
        this.ActiveControl.Parent.Select();
}

Hope this helps!