用回车键代替Tab键(100分)

  • 主题发起人 柏伟民
  • 开始时间

柏伟民

Unregistered / Unconfirmed
GUEST, unregistred user!
请教:如何用回车健代替Tab键在窗体中移动焦点?
 
在onkeydown里面令如果key值为vk_enter,令key等于tab的健值(可能是vk_tab)好像可以
 
把Form的KeyPreview属性设为True
在Form的OnKeyDown事件处理程序中:
if Key = VK_RETURN then
begin
Key := VK_TAB;
FindNextControl(ActiveControl, True, True, False).SetFocus;
end
 
Procedure TForm1.FormKeyPress(Sender:Tobject;Var Key:Char);
Begin
 if key=#13 then { 判断是按执行键}
 if not (ActiveControl is TDbgrid) Then
 Begin { 不是在TDbgrid控件内}
  key:=#0;
  perform(WM_NEXTDLGCTL,0,0);{移动到下一个控件}
 end else
 if (ActiveControl is TDbgrid) Then{是在 TDbgrid 控件内}
 begin
  With TDbgrid(ActiveControl) Do
  if Selectedindex<(FieldCount-1) then
  Selectedindex:=Selectedindex+1{ 移动到下一字段}
  else Selectedindex:=0;
 end;
End;

下面方法也行:
if Key = #13 then
begin
Key := #0;
Perform (CM_DialogKey, VK_TAB, 0);
end;
 
在keypress事件中
key:=0;
findnextcontrol(activecontrol,true,true,false).setfocus;
 
把Form1的KeyPreview设为True
在Form1的OnKeyPress事件中加入:
Procedure ...
begin
if key = #13 then
SelectNext(ActiveControl,True,True);
end;
 
把Form1的KeyPreview设为True
在Form1的OnShortCut事件中加入:
if Messages.CharCode=13 then
Messages.CharCode=VK_TAB
不要设置Handled
 
发送 WM_NEXTDLGCTL 消息是比较好的办法。
 
把Form1的KeyPreview设为True
在Form1的OnKeyPress事件中加入:
Procedure ...
begin
if key = #13 then
……。setfocus //
end;
 
找一找就知道了
 
把Form1的KeyPreview设为True
在Form1的OnKeyPress事件中加入:
procedure TGoodsAEForm.FormKeyPress(Sender: TObject
var Key: Char);
begin
if Key=#13 Then
begin
Key:=#0;
PerForm(WM_NEXTDLGCTL,0,0);
end;
end;
包你用的开心!不过在有DBGrid控件的FORM中,还要加一些程序。
如果要,请来信告知!邮给你。
 
程序员大本营2000上面有这个技巧的介绍,无非就是接收键盘的输入,转化成为对应的处理,
我原来老师让我们实现这个功能,但是我本人一直怀疑这么做的用处
 
拜托大家不要再提这个问题了~~
 
在OnKeyPress事件里:
if Key = #13 then
SendMessage(0,Wm_KeyDown,Vk_Tab,0);
 
最好最簡單方法:

if Key = #13 then
begin
Key := #0;
Perform (CM_DialogKey, VK_TAB, 0);
end;

快給分呀!老兄...
 
if Key = #$D then
begin
PostMessage(Handle,WM_KEYDOWN,VK_TAB,0);
Key := #0;
end;
 
还有一个最简单的方法!用一个叫dosmove的控件!
 
多人接受答案了。
 

Similar threads

顶部