开发者

Delphi Getting 'Ctrl Tab' and 'Ctrl Shift Tab' in application

开发者 https://www.devze.com 2022-12-21 09:46 出处:网络
In my application I use tabs, my own component, like Google chrome sort of. Each tab reference an explorer component so it is basicly a tabbed browser/explorer. My problem is that I want to use CTRL+

In my application I use tabs, my own component, like Google chrome sort of. Each tab reference an explorer component so it is basicly a tabbed browser/explorer. My problem is that I want to use CTRL+ TAB and CTRL+SHIFT +TAB to navigate tabs. Setting forms.KeyPreview will not help since the tab key is special key. How can I, in an easy way, add support for my navigation wish. I can modify compo开发者_JAVA技巧nent if needed. My component is based on TCustomControl if that helps.

Kind Regards Roy M Klever


Tab, like the arrow keys, enter and escape are a special keys used in dialog navigation. When a control would like to receive those keys it has to indicate so by responding to WM_GETDLGCODE. Like this code below. Then you will receive a KeyDown event when Tab is pressed.

procedure WMGetDlgCode(var Msg: TWMGetDlgCode); message WM_GETDLGCODE;

procedure TYourControl.WMGetDlgCode(var Msg: TWMGetDlgCode);
begin
 inherited;
 Msg.Result := Msg.Result or DLGC_WANTTAB;
end;

Also see here and here.

PS: And make sure your control has focus or you will receive nothing at all (if CanFocus then SetFocus; in MouseDown).


You can manage the CM_DIALOGKEY message in your component to intercept the Ctrl + Tab and Ctrl + Shift + Tab.

procedure CMDialogKey(var Message: TCMDialogKey); message CM_DIALOGKEY;

check this sample

procedure TYourComponent.CMDialogKey(var Message: TCMDialogKey);
begin
  if (Focused) and (Message.CharCode = VK_TAB) and (GetKeyState(VK_CONTROL) < 0) then
  begin
   if GetKeyState(VK_SHIFT) then
    GoBackwardPage()//you must write this method
   else
    GoForwardPage()//you must write this method
    Message.Result := 1;
  end
   else
    inherited;
end;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号