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(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (ssCtrl in Shift) and (Ord(Key) = VK_TAB) then
begin
if ssShift in Shift then
if TabControl.tabIndex > 0 then
TabControl.TabIndex := TabControl.tabIndex - 1
else
TabControl.TabIndex := TabControl.tabs.Count - 1
//end if
else
if TabControl.tabIndex < TabControl.Tabs.Count - 1 then
TabControl.TabIndex := TabControl.tabIndex + 1
else
TabControl.TabIndex := 0;
//end if
//end if
FocusControl(TabControl);
TabControl.OnChange(self);
end;
end;
Mason
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.