如何让TPanel响应OnKeyPress事件!(100分)

Y

ydy

Unregistered / Unconfirmed
GUEST, unregistred user!
如何让TPanel响应OnKeyPress事件!
 
大侠帮帮忙!!
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Panel1: TPanel;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
OldWinProc :TWndMethod;
procedure MyPanelWindProc(var message:tmessage);

public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
Panel1.TabStop := true;
OldWinProc := Panel1.WindowProc;
Panel1.WindowProc := MyPanelWindProc;
end;
procedure TForm1.MyPanelWindProc(var message:tmessage);
begin

if message.Msg = wm_keypress then
begin
//add your code here;
end;
OldWinProc(message);
end;
end.
 
为什么一定要PANEL?
 
Panel没有焦点不可能接收到Key的事件
 
我有一个这样的例程,告诉我你的信箱,我发给你!
 
多人接受答案了。
 
顶部