M meemei Unregistered / Unconfirmed GUEST, unregistred user! 2007-11-06 #1 比如我的form上有两个控件,一个是Text,一个是ComboBox,用户在其中一个控件上按了F1,我怎么知道是哪一个控件呢?
L lovedesky Unregistered / Unconfirmed GUEST, unregistred user! 2007-11-06 #3 procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key=VK_F1 then showmessage('Edit'); end; procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key=VK_F1 then showmessage('ComboBox'); end;
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key=VK_F1 then showmessage('Edit'); end; procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key=VK_F1 then showmessage('ComboBox'); end;
M meemei Unregistered / Unconfirmed GUEST, unregistred user! 2007-11-06 #4 lovedesky,你的做法我知道,但是这个做法的效率很低,不利于维护。如果有50个控件我就要写50个地方了,我希望能只写在一个地方,将来维护方便。
S snail2233 Unregistered / Unconfirmed GUEST, unregistred user! 2007-11-06 #5 1.Form.KeyPreview:=True; 2.Form.OnKeyDown(xxx) begin if Key = F1的键盘码 then ShowMessage(ActiveControl.Name); end;
1.Form.KeyPreview:=True; 2.Form.OnKeyDown(xxx) begin if Key = F1的键盘码 then ShowMessage(ActiveControl.Name); end;
L lovedesky Unregistered / Unconfirmed GUEST, unregistred user! 2007-11-06 #6 顶snail2233。。学习ing~~~~一直在想用消息机制的方法解决,不过还没有找到方法,就看到snail2233的答案已经出来了,呵呵[]
A ANiDelphi Unregistered / Unconfirmed GUEST, unregistred user! 2007-11-06 #8 procedure TForm1.FormShortCut(var Msg: TWMKey; var Handled: Boolean); begin if Msg.CharCode = VK_F1 then if ActiveControl <> nil then Caption := ActiveControl.Name else Caption := Name; end;
procedure TForm1.FormShortCut(var Msg: TWMKey; var Handled: Boolean); begin if Msg.CharCode = VK_F1 then if ActiveControl <> nil then Caption := ActiveControl.Name else Caption := Name; end;