Q&A

  • 키다운, 키업 이벤트를 가진 컴포넌트를 만들라면 어떻게 해야 하나요?
안녕하세요..영원한 델초보 어린왕자입니다.

키다운, 키업 이벤트가 컴포넌트에 안들어가나요?



type

TMyCom = class(TWincontrol)

publish

Property OnKeyDown;

Property OnKeyUp;

end;



이렇게 하면 되지 않나요?







***** 운영자님에 의해서 게시물 카테고리변경되었습니다 (2004-10-19 18:07)
3  COMMENTS
  • Profile
    김일영 2001.10.23 04:33
    간만의 [컴포넌트개발] 분류로군요...

    (다음엔 분류를 해 주시겠죠?)



    맞는 방법입니다.

    그렇게만 선언하시면 됩니다.



    Controls 유닛을 보시면



    TWinControl = class(TControl)

    .....

    protected

    ....

    property OnKeyDown: TKeyEvent read FOnKeyDown write FOnKeyDown;

    property OnKeyPress: TKeyPressEvent read FOnKeyPress write FOnKeyPress;

    property OnKeyUp: TKeyEvent read FOnKeyUp write FOnKeyUp;

    .....



    이렇게 되어 있고요.



    Forms 유닛을 보시면



    TForm = class(TCustomForm)

    .....

    published

    .....

    property OnKeyDown;

    property OnKeyPress;

    property OnKeyUp;

    .....



    이렇게 되어 있습니다.



    TCustomForm - TScrollingWinControl에서는 해 주는 것이 없습니다.



    수고하십시오.









    어린왕자A wrote:

    > 안녕하세요..영원한 델초보 어린왕자입니다.

    > 키다운, 키업 이벤트가 컴포넌트에 안들어가나요?

    >

    > type

    > TMyCom = class(TWincontrol)

    > publish

    > Property OnKeyDown;

    > Property OnKeyUp;

    > end;

    >

    > 이렇게 하면 되지 않나요?

    >





    ***** 운영자님에 의해서 게시물 카테고리변경되었습니다 (2004-10-19 18:07)
  • Profile
    어린왕자A 2001.10.23 18:38
    근데..아니되더군요..

    누가 만드신 IP입력컨트롤인데..

    저가 좀 수정할라구..(__);;

    중간에 누가 메세지를 훔쳐가서 그런걸까요?

    키를 눌러도..이벤트 핸들러를 부르지 않아요..(__);



    김일영 wrote:

    > 간만의 [컴포넌트개발] 분류로군요...

    > (다음엔 분류를 해 주시겠죠?)

    >

    > 맞는 방법입니다.

    > 그렇게만 선언하시면 됩니다.

    >

    > Controls 유닛을 보시면

    >

    > TWinControl = class(TControl)

    > .....

    > protected

    > ....

    > property OnKeyDown: TKeyEvent read FOnKeyDown write FOnKeyDown;

    > property OnKeyPress: TKeyPressEvent read FOnKeyPress write FOnKeyPress;

    > property OnKeyUp: TKeyEvent read FOnKeyUp write FOnKeyUp;

    > .....

    >

    > 이렇게 되어 있고요.

    >

    > Forms 유닛을 보시면

    >

    > TForm = class(TCustomForm)

    > .....

    > published

    > .....

    > property OnKeyDown;

    > property OnKeyPress;

    > property OnKeyUp;

    > .....

    >

    > 이렇게 되어 있습니다.

    >

    > TCustomForm - TScrollingWinControl에서는 해 주는 것이 없습니다.

    >

    > 수고하십시오.

    >

    >

    >

    >

    > 어린왕자A wrote:

    > > 안녕하세요..영원한 델초보 어린왕자입니다.

    > > 키다운, 키업 이벤트가 컴포넌트에 안들어가나요?

    > >

    > > type

    > > TMyCom = class(TWincontrol)

    > > publish

    > > Property OnKeyDown;

    > > Property OnKeyUp;

    > > end;

    > >

    > > 이렇게 하면 되지 않나요?

    > >





    ***** 운영자님에 의해서 게시물 카테고리변경되었습니다 (2004-10-19 18:07)
  • Profile
    김일영 2001.10.23 22:29
    잘 되는데요.

    아마도 그 컨트롤에 Focus가 안가서 그럴겁니다.

    아래는 제가 실제로 해 본 소스입니다. 참고하시죠.



    unit Unit1;



    interface



    uses

    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;



    type

    TTestControl = class(TWinControl)

    published

    property OnKeyDown;

    property OnKeyPress;

    property OnKeyUp;

    end;



    type

    TForm1 = class(TForm)

    procedure FormCreate(Sender: TObject);

    procedure FormShow(Sender: TObject);

    private

    { Private declarations }

    FTestControl: TTestControl;

    procedure TestControlKeyDown(Sender: TObject; var Key: Word;

    Shift: TShiftState);

    public

    { Public declarations }

    end;



    var

    Form1: TForm1;



    implementation



    {$R *.DFM}



    procedure TForm1.FormCreate(Sender: TObject);

    begin

    FTestControl := TTestControl.Create(Self);

    FTestControl.Parent := Self;

    FTestControl.Align := alClient;

    FTestControl.Color := clGreen;

    FTestControl.OnKeyDown := TestControlKeyDown;

    end;



    procedure TForm1.FormShow(Sender: TObject);

    begin

    ActiveControl := FTestControl; // FTestControl에 포커스를 줍니다.

    end;



    procedure TForm1.TestControlKeyDown(Sender: TObject; var Key: Word;

    Shift: TShiftState);

    begin

    ShowMessage('KeyDown');

    end;



    end.