Recently really really too busy, so that one months did not yo update my blog. Last night, an online friend read my toolbox article, asked me a question, he said how to make the Toolbox control can also respond to keyboard operation, that is, use the Up,down button to select the item in the Toolbox control, he added keyboard events, but does not work. The first time to do this control is also just a demonstration of the control of the production process, only a very short time to do one, only to consider using the mouse to select, did not consider the keyboard operation, I want to add keyboard operation is nothing more than overloading KeyDown events, for Up,down do some response on it. But after adding the overloaded onkeydown event, the result and that friend said, no effect, I set a point, debugging, found that KeyDown can not capture up at all, down button clicks, what is the reason, is not forget to set the style of control so that it can get focus? So, I used the statement:
SetStyle (controlstyles.selectable, true); still no effect, when we press down on the control, another control gets the focus. At this point the Up,down button just plays the role of navigation like the TAB key.
Next, I put a ListBox control on the test project's form to make a comparison, in fact, Toolbox and the ListBox have similarities in the interface performance, that is, there are child item, and click on the listbox is working, the listbox did not lose focus , which means that the Up,down key does not become the navigation key. I think windows must have a default handle on the default navigation key up,down,left,right unless you want your control to want to handle the keys yourself. Look at the source code of the Listboxcontrol control with the Disassembly tool and discover an interesting function:
protected override bool isInputKey (Keys keyData)
{
if (keyData & keys.alt) = = Keys.alt)
{
return false;
switch ((KeyData & Keys.keycode))
{case
keys.prior: Case
Keys.next:
Case Keys.end: Case
Keys.home: Return
true;
Return to
base. isInputKey (KeyData);
}