可以用form窗体本身的shortcut事件
if msg.CharCode =13 then
showmessage('ok');
然后定义消息传送给 image的两个事件分别处理,我觉得能满足你的需求。
if msg.CharCode =13 then
showmessage('ok');
然后定义消息传送给 image的两个事件分别处理,我觉得能满足你的需求。
解决方案 »
- 为什么会除错?
- 关于IMAGE组件!!
- 请教,Query+UpdateSql 更新时出现 Update failed
- 使用TOleContainer控件调用excel后为什么不能正确打开excel文档?(在线等待)
- 关于浮点数验证的问题!
- 请教SQL语句问题
- 急,RX控件 求助!!PrintPageType Property doesn't exist---RXlib for D5(RxDBGrid)
- Delphi里让输入Edit的字符变成‘*’的属性是什么?
- 请问:怎样求出记录指针所在的记录是整个表中的第几位?
- 30分求知:regedit是怎样控制用户使用的程序??即不允许用户使用!!
- Delphi2006操作MySQL出错,是我的问题还是Delphi2006本身的问题?
- VC的数据类型对应Delphi里的数据类型?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, jpeg;
const WM_USER_1 = WM_USER + 8003;
const WM_USER_2 = WM_USER + 8004;type
TForm1 = class(TForm)
Image1: TImage;
procedure FormShortCut(var Msg: TWMKey; var Handled: Boolean);
private
{ Private declarations }
procedure setClick(var Msg: TMessage); Message WM_USER_1;
procedure setMove(var Msg: TMessage); Message WM_USER_2;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.setClick(var Msg: TMessage);
begin
Showmessage('click');
end;procedure TForm1.setMove(var Msg: TMessage);
begin
showmessage('mousemove');
end;procedure TForm1.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
if msg.CharCode = 13 then
sendMessage(handle,WM_USER_1,0,0);
if msg.CharCode = 112 then
sendMessage(handle,WM_USER_2,0,0);
end;end.
---这是图形控件的特点.
讲的好啊.....
我以下的代码是通过光标键在Image上画线:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;type
TForm1 = class(TForm)
Image1: TImage;
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
dx,dy:Integer;
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
nx,ny:Integer;
begin
nx:=dx;
ny:=dy;
case Key of
VK_UP:
if dy>0 then Dec(dy);
VK_DOWN:
if dy<Height then Inc(dy);
VK_LEFT:
if dx>0 then Dec(dx);
VK_RIGHT:
if dx<Width then Inc(dx);
end;
if(nx<>dx)or(ny<>dy)then
Image1.Canvas.LineTo(dx,dy);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
KeyPreview:=True;
Image1.Align:=alClient;
dx:=20;
dy:=20;//初始化作图坐标
Image1.Canvas.MoveTo(dx,dy);
end;end.
设置
Form.KeyPreview := True;
然后在OnkeyPress中写你的代码。。
要先设置form的KeyPreview的。
真是弱智问题。
几年不用D了,都忘光光了,寒自己一个……
和所有回帖的人对话是我的传统,大家各取所需,不要嫌我啰嗦。
TO solokey(争取在2008年成为低级程序员):22个字符,100分。高效,BTW:we have same goal. (争取在2008年成为低级程序员)^_^。
TO liangqingzhi(老之)、fireball64(fireball):只有Form上没有可以获得焦点的控件时,Form才会获得焦点。这点你可以查TCustomForm的SetFocus过程的帮助。
TO zxf_feng(阿日):虽然我没有试,相信你的方法不失可行,但是有点杀鸡用牛刀了。另外,你不笨,比我强多了,我是狗熊掰棒子,记忆力超差……所有好学的人都不笨。
TO cccbbbz_cn(狼的智慧) 也许你说得不错,但我保留个人意见:如果我不用Image而是在Form的Canvas上直接画,可能更节约资源。
TO mastersky(浪) :完成Mission Impossible不正是创作的乐趣吗?
TO hmzgz81(哩翱)、wizardqi(男巫)、wxh850619() 、FigoZhu(谢慕安):早起的鸟儿有食吃,不好意思,你们吃了点,下次吧。
TO gerrylc(lc) 、 pp_ipr(ikn)、 wtg476(起飞)、 baiduan(小安子) 、 yaccor(我实在不想起这么长的名字实在是因为我已经不会起名字我还想顺便看看这个网站到底允许我起多长的名字) 、j9dai(DoItNow) :Thanks for your ups.
另 to liangqingzhi(老之):你也姓梁?
=================
对,我们五百年前是一家?