PDA

View Full Version : <CTRL>-<TAB> and TTabControls



masonwheeler
09-08-2007, 01:21 PM
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

Robert Kosek
09-08-2007, 01:58 PM
You'll have to do an OnKeyPress event, perhaps on the parent form or panel. Other than that I don't know.

masonwheeler
15-08-2007, 02:57 PM
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:


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