用方向键控制焦点(100分)

  • 主题发起人 主题发起人 少爷的拐杖
  • 开始时间 开始时间

少爷的拐杖

Unregistered / Unconfirmed
GUEST, unregistred user!
窗体上有很多Edit,我想按下键的时候焦点下移,按上的时候<br>焦点上移。(Edit们的Tab顺序已经调整好。)<br>比如:<br>我在Edit5里按方向键“上”,Edit4获得焦点,<br>我在Edit5里按方向键“下”,Edit6获得焦点,<br>查询旧贴未果,献上区区100大元,不成敬意。
 
我在这里等着呢?怎么没人说两句啊?
 
procedure TfrmI20Rkd_Kby.FormKeyDown(Sender: TObject; var Key: Word;<br>&nbsp; Shift: TShiftState);<br>begin<br>&nbsp; if not (ActiveControl is TwwDbGrid) then begin //不是在TDBGRID控件内<br>&nbsp; &nbsp; case Key of<br>&nbsp; &nbsp; &nbsp; VK_Return:<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Key := Word(#0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ssShift in Shift then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Perform(WM_NextDLGCTL, 1, 0)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Perform(WM_NEXTDLGCTL, 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; VK_UP:<br>&nbsp; &nbsp; &nbsp; &nbsp; if not (ActiveControl is TwwDBLookupCombo) then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Key := Word(#0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Perform(WM_NEXTDLGCTL, 1, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;
 
我试了一下,不起作用呀。是不是还要设置什么属性?
 
全面解决方案:)<br><br>form的属性keyPreview=true;//注意<br><br>procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;<br>&nbsp; Shift: TShiftState);<br>begin<br>case key of<br>&nbsp; &nbsp; 38:Perform(WM_NextDLGCTL, 1, 0);<br>&nbsp; &nbsp; 40:Perform(WM_NextDLGCTL, 0, 0);<br>end;<br>end;<br>我试过了,可以<br>兄弟,给分吧:)<br><br>
 
多人接受答案了。
 
后退
顶部