Link to home
Create AccountLog in
Avatar of intercad
intercad

asked on

TComboBox Enter as Tab behaviour

Hi,

I defined a new component derived from TComboBox  to automate de usage of the Enter key as Tab and other minor stuff. On TEdit control it worked all right. On TComboBox the event handler KeyPress is raised twice for each Enter key press, as a result one control is always jumped in the tab order list. I only tested with DropDownList style.

The application is quite big so I really want to go forward with the new class approach.

Tests I made so far:

Using Perform instead of PostMessage doesn't help.

BackSpace key works all right (is only processed once).

Using KeyUp instead of KeyPress as the same result but with a different behaviour. TComboBox seems to handle the Enter given to the previous control and jumps to the following control.

I really need some help here.

Thanks in advance for all the help.

Vieira da Silva

Here is the code skeleton, the register procedure is on another unit.

unit ProM_ComboBox;

interface

uses
  Windows, SysUtils, Classes, Controls, StdCtrls;

type
  TProM_ComboBox = class(TComboBox)
  protected
    { Protected declarations }
    procedure KeyPress(var Key: Char); override;
  end;

implementation

uses
  Messages, Dialogs;

procedure TProM_ComboBox.KeyPress(var Key: Char);
begin
  MessageDlg(IntToStr(Ord(Key)), mtInformation, [mbOK], 0);      // Debug
  if Key = Char(VK_RETURN) then
    if Owner is TWinControl then
      PostMessage((Owner as TWinControl).Handle, WM_NEXTDLGCTL, 0, 0);

  inherited KeyPress(key);
end;

end.
ASKER CERTIFIED SOLUTION
Avatar of Greybird
Greybird

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of intercad
intercad

ASKER

I could I have missed that...

Thanks a lot.