Results 1 to 3 of 3

Thread: <CTRL>-<TAB> and TTabControls

  1. #1

    <CTRL>-<TAB> and TTabControls

    I put a TTabControl on my form, and to my great surprise, I'm not able to switch between tabs with <CTRL>-<TAB> at runtime. I thought this was default behavior; every app I've ever used with a tabbed control will do this. How do I implement the behavior, so that if I press <CTRL>-<TAB> or <CTRL>-<SHIFT>-<TAB> in a form with a TTabControl on it, no matter which component currently has the focus, the TTabControl will move to the next (or previous) tab and call it's onChange event?

    Mason

  2. #2

    <CTRL>-<TAB> and TTabControls

    You'll have to do an OnKeyPress event, perhaps on the parent form or panel. Other than that I don't know.

  3. #3

    <CTRL>-<TAB> and TTabControls

    I asked somewhere else and managed to get a working solution. Here it is, in case anyone else has this question later on.

    First off, set KeyPreview to True on the form. Then add this event handler:

    Code:
    procedure TfrmMyForm.FormKeyDown&#40;Sender&#58; TObject; var Key&#58; Word;
      Shift&#58; TShiftState&#41;;
    begin
       if &#40;ssCtrl in Shift&#41; and &#40;Ord&#40;Key&#41; = VK_TAB&#41; then
       begin
          if ssShift in Shift then
             if TabControl.tabIndex > 0 then
                TabControl.TabIndex &#58;= TabControl.tabIndex - 1
             else
                TabControl.TabIndex &#58;= TabControl.tabs.Count - 1
             //end if
          else
             if TabControl.tabIndex < TabControl.Tabs.Count - 1 then
                TabControl.TabIndex &#58;= TabControl.tabIndex + 1
             else
                TabControl.TabIndex &#58;= 0;
             //end if
          //end if
          FocusControl&#40;TabControl&#41;;
          TabControl.OnChange&#40;self&#41;;
       end;
    end;
    Mason

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •