急!上下键问题!!! form中有多个BitBtn,我想在BitBtn间用上下键来移动。但是,经测试,在TForm1.FormKeyDown事件中,键盘输入上下键,FormKeyDown事件却无法相应。如果是输入其他按键都可以相应FormKeyDown事件。怪怪啊! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你可以试试unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;type TMyButton=class(Tbutton) private procedure CMWantSpecialKey(var Message: TCMWantSpecialKey); message CM_WANTSPECIALKEY;end;var Form1: TForm1;implementation{$R *.dfm}procedure TMyButton.CMWantSpecialKey(var Message: TCMWantSpecialKey); begininherited;// 我们只想处理向左方向键,其它的特殊键都给 Windows 处理 case Message.CharCode of VK_UP : showmessage('Up'); VK_Down: showmessage('Down'); end; Message.Result := 1;end;procedure TForm1.FormCreate(Sender: TObject);var Button1,button2:Tmybutton;begin button1:=Tmybutton.Create(nil); button1.Parent:=self; button1.Left:=100; button1.Top:=100; button1.Caption:='button1'; button2:=Tmybutton.Create(nil); button2.Parent:=self; button2.Left:=100; button2.Top:=200; button2.Caption:='button2';end;end. 窗体的KeyPreview设置成true;在窗体事件procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin case Key of VK_UP : self.Perform(WM_NEXTDLGCTL,0,0); VK_Down: self.Perform(WM_NEXTDLGCTL,1,0); end; Key := 0;end; 用message实现了]你找以下资料很都的 没有大家讲的这么复杂吧其实在 object inspector 里设置taborder 的属性例如 BitBtn1为1,BitBtn2为2,BitBtn3为3,这样应该可以的 如果只有bitbtn,确实默认上下键就可以了;否则按lynmison(菻梓) 说的不错 反了,窗体的KeyPreview设置成true;在窗体事件procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin case Key of VK_UP : self.Perform(WM_NEXTDLGCTL,1,0); VK_Down: self.Perform(WM_NEXTDLGCTL,0,0); end; Key := 0;end; sql server重新连接 如何使打开的文件在关闭时自动在电脑上删除 拦截消息处理 如何快速提取txt文件中2万条记录?? 此问题在以前看过,现在又找不到了,麻烦大家再给我透露一下。谢谢!! 怎么写进数据库 急! 请教2个网络方面的问题.. 怎样使用PrintDBGridEh1打印DBGridEh1的空表格? 请大家帮忙解决一个问题 共享一套老版本天心ERP源码 有想做兼职的没,在上海! 如何执行DOS命令?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type TMyButton=class(Tbutton)
private
procedure CMWantSpecialKey(var Message: TCMWantSpecialKey); message CM_WANTSPECIALKEY;
end;
var
Form1: TForm1;implementation{$R *.dfm}
procedure TMyButton.CMWantSpecialKey(var Message: TCMWantSpecialKey); begin
inherited;
// 我们只想处理向左方向键,其它的特殊键都给 Windows 处理
case Message.CharCode of
VK_UP : showmessage('Up');
VK_Down: showmessage('Down');
end;
Message.Result := 1;
end;
procedure TForm1.FormCreate(Sender: TObject);
var Button1,button2:Tmybutton;
begin
button1:=Tmybutton.Create(nil);
button1.Parent:=self;
button1.Left:=100;
button1.Top:=100;
button1.Caption:='button1';
button2:=Tmybutton.Create(nil);
button2.Parent:=self;
button2.Left:=100;
button2.Top:=200;
button2.Caption:='button2';
end;end.
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin case Key of
VK_UP : self.Perform(WM_NEXTDLGCTL,0,0);
VK_Down: self.Perform(WM_NEXTDLGCTL,1,0);
end;
Key := 0;end;
你找以下资料很都的
其实在 object inspector 里设置taborder 的属性例如 BitBtn1为1,BitBtn2为2,BitBtn3为3,
这样应该可以的
否则按lynmison(菻梓) 说的不错
窗体的KeyPreview设置成true;在窗体事件procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin case Key of
VK_UP : self.Perform(WM_NEXTDLGCTL,1,0);
VK_Down: self.Perform(WM_NEXTDLGCTL,0,0);
end;
Key := 0;end;