BCB处理Tab按键事件

默认的Edit等控件不能处理Tab按键,只能在Form的OnShortCut事件处理

关于OnShortCut帮助

Use OnShortCut to dispatch shortcut keystrokes before the form handles them. When the user presses a key, the form can dispatch it as a shortcut key instead of allowing the standard keystroke processing (OnKeyDown, OnKeyPress, and OnKeyUp). Built-in shortcut processing is provided for menu shortcuts and actions associated with the form. OnShortCut allows the form to implement additional shortcuts.


If the OnShortCut implements a response to the keystroke, set the Handled parameter of the event handler to true. This prevents the keystroke from being passed on to menus or actions associated with the form. It also prevents the standard keystroke processing in the same way that a menu or action shortcut does.

想让Edit之类控件处理Tab消息的解决办法:

在OnShortCut检测到Tab按键消息返回0(未处理),则Tab按键消息会被发送到相应的控件(默认不发送)

void __fastcall TForm1::FormShortCut(TWMKey &Msg, bool &Handled)
{
  if(Msg.CharCode==VK_TAB)
  Msg.Result=0;   
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Edit1KeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
   ShowMessage(Key);      
}


你可能感兴趣的:(user,processing,action,menu)