2009. április 23., csütörtök

Navigate a TPageControl using Ctrl-Tab and Ctrl-Shift-Tab if several pagecontrols are on a form


Problem/Question/Abstract:

I have a PageControl having 3 TabSheets. If this PageControl has a Panel as its parent, then I am able navigate between the tabsheets using Ctrl-Tab (forward) or Shift-Ctrl-Tab (backward) using the keyboard. But if the same pagecontrol has another Tabsheet of a Pagecontrol as its parent, then I am not able to navigate between the tabsheets of the child pagecontrol using the keyboard even though the focus is on the child pagecontrol.

Answer:

Handling proper Ctrl-Tab and Ctrl-Shift-Tab switching of pages if several pagecontrols are on a form:

In form declaration:

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

procedure TForm1.CMDialogKey(var msg: TCMDialogKey);
var
  Control: TWinControl;
begin
  with Msg do
  begin
    if (charcode = VK_TAB) and (GetKeyState(VK_CONTROL) < 0) then
    begin
      Control := ActiveControl;
      while Assigned(Control) do
        if Control is TPageControl then
        begin
          Control.Perform(CM_DIALOGKEY, charcode, keydata);
          Exit;
        end
        else
          Control := Control.Parent;
    end;
  end;
  inherited;
end;

Nincsenek megjegyzések:

Megjegyzés küldése