如何用方向键在几个组件间进行切换(100分)

R

rice

Unregistered / Unconfirmed
GUEST, unregistred user!
比如说有6个TEdit组件,排成3行2列。要求用光标控制它们之间的切换,<br>当输入焦点位于Tedit的字符串首时,按向右键,移动到下一个字符;<br>&nbsp; &nbsp; 按向左键,输入焦点移至上一个Tedit组件;<br>当输入焦点位于Tedit的字符串尾时,按向左键,移动到上一个字符;<br>&nbsp; &nbsp; 按向右键,输入焦点移至下一个Tedit组件;<br>当输入焦点位于Tedit的字符串中间时,按左右键,光标分别向相应<br>&nbsp; &nbsp; 的方向移动。<br>我知道要用API实现,不过不知用什么函数实现,怎么实现???<br>CAN YOU HELP ME!!!!!<br><br><br>
 
用以下过程捕获方向键:<br>procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;<br>&nbsp; Shift: TShiftState);<br>begin<br>&nbsp; case key of<br>&nbsp; &nbsp; VK_UP:showmessage('up key');<br>&nbsp; &nbsp; VK_DOWN:showmessage('down key');<br>&nbsp; &nbsp; VK_LEFT:showmessage('left');<br>&nbsp; &nbsp; VK_RIGHT:showmessage('right');<br>&nbsp; end;<br>end;<br>捕获到按键之后该怎么做,你应该知道吧?
 
不好意思,你说的正好我知道,反而按键之后怎么处理不知道。<br>请不吝赐教!!!!Thanks!!!
 
如何在捕获方向键后,控制光标的移动?????
 
然后就 setfocus ,使焦点移动
 
这是以前一个大富翁上的朋友写的构件,你看看是否可以用:<br>unit quickkey;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls, Grids, ExtCtrls, typinfo, math;<br><br>type<br>&nbsp; TMoveOptions = set of (moEditDeliver, moListDeliver,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;moComboDeliver,moGridDeliver, moButtonDeliver,moRadioDeliver);<br><br>&nbsp; TQuickKey = class(TComponent)<br>&nbsp; private<br>// &nbsp; &nbsp;FComponents: TList;<br>&nbsp; &nbsp; FActive: boolean;<br>&nbsp; &nbsp; FOwnerKeyEvents &nbsp;: TMessageEvent;<br>&nbsp; &nbsp; FOptions : TMoveOptions;<br><br>&nbsp; &nbsp; FEdit : Boolean;<br>&nbsp; &nbsp; FList : Boolean;<br>&nbsp; &nbsp; FGrid : boolean;<br>&nbsp; &nbsp; FCombo : boolean;<br>&nbsp; &nbsp; FButton : boolean;<br>&nbsp; &nbsp; FRadio: boolean;<br>&nbsp; &nbsp; function MoveUpSide(Sender: TWinControl;Key: word):boolean;<br>&nbsp; &nbsp; function MoveDownSide(Sender: TWinControl;Key: word):boolean;<br>&nbsp; &nbsp; function MoveLeftSide(Sender: TWinControl;Key: word):boolean;<br>&nbsp; &nbsp; function MoveRightSide(Sender: TWinControl;Key: word):boolean;<br>&nbsp; &nbsp; function MoveNextSide(Sender: TWinControl;Key: word):boolean;<br>&nbsp; &nbsp; procedure GetControl(Sender: TWinControl;Direct: integer);<br>&nbsp; &nbsp; function CanEnterKey(Sender: TWincontrol): boolean;<br>&nbsp; &nbsp; function HasProperty(Sender: TObject; AProperty: string):boolean;<br>&nbsp; &nbsp; function TestProperty(Sender: TObject; AProperty: string;<br>&nbsp; &nbsp; &nbsp; &nbsp;Value: integer): boolean;<br>&nbsp; &nbsp; function GetPropertyValue(Sender: TObject; AProperty: string): integer;<br>&nbsp; protected<br>&nbsp; &nbsp; { Protected declarations }<br>&nbsp; public<br>&nbsp; &nbsp; procedure NewKeyDown(var Msg: TMsg; var Handled: boolean);<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; &nbsp; constructor Create(AOwner : TComponent); override;<br>&nbsp; &nbsp; destructor Destroy; override;<br>&nbsp; published<br>&nbsp; &nbsp; { Published declarations }<br>&nbsp; &nbsp; property Active: boolean read FActive write FActive;<br>&nbsp; &nbsp; property Options : TMoveOptions read FOptions write FOptions<br>&nbsp; &nbsp; &nbsp; default [moEditDeliver, moListDeliver,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;moGridDeliver, moButtonDeliver];<br>&nbsp; end;<br><br>procedure Register;<br><br>implementation<br><br>procedure Register;<br>begin<br>&nbsp; RegisterComponents('freeware', [TQuickKey]);<br>end;<br><br>constructor TQuickKey.Create(AOwner: TComponent);<br>var<br>&nbsp; &nbsp;Loop: integer;<br>begin<br>&nbsp; for Loop:=0 to AOwner.ComponentCount-1 do<br>&nbsp; &nbsp; if AOwner.Components[Loop] is TQuickKey then raise<br>&nbsp; &nbsp; &nbsp; EInvalidOperation.Create(<br>&nbsp; &nbsp; &nbsp; &nbsp; 'TQuickKey can have only one instance per form');<br><br>&nbsp; // Create component and set default properties<br>&nbsp; inherited Create(AOwner);<br>&nbsp; FActive:=false;<br><br>&nbsp; FOptions:=[moEditDeliver, moListDeliver,<br>&nbsp; &nbsp; &nbsp; moComboDeliver,moGridDeliver, moButtonDeliver, moRadioDeliver];<br><br>&nbsp; FOwnerKeyEvents:=Application.OnMessage;<br>&nbsp; Application.OnMessage:=NewKeyDown;<br>end;<br><br>destructor TQuickKey.Destroy;<br>begin<br>&nbsp; Application.OnMessage:=FOwnerKeyEvents;<br>&nbsp; inherited;<br>end;<br><br>procedure TQuickKey.NewKeyDown(var Msg: TMsg; var handled: boolean);<br>var<br>&nbsp; v: TWinControl;<br>&nbsp; f: TForm;<br>begin<br>&nbsp; if FActive then<br>&nbsp; begin<br>&nbsp; &nbsp; f:=self.owner as TForm;<br>&nbsp; &nbsp; if f.Active and (Msg.message=WM_KEYDOWN) then<br>&nbsp; &nbsp; if<br>&nbsp; &nbsp; (Msg.wParam = VK_RETURN) or<br>&nbsp; &nbsp; (Msg.wParam = VK_LEFT) or<br>&nbsp; &nbsp; (Msg.wParam = VK_RIGHT) or<br>&nbsp; &nbsp; (Msg.wParam = VK_UP) or<br>&nbsp; &nbsp; (Msg.wParam = VK_DOWN) &nbsp;then begin<br>&nbsp; &nbsp; &nbsp; v:=f.ActiveControl;<br>&nbsp; &nbsp; &nbsp; FEdit := v is TCustomEdit;<br>&nbsp; &nbsp; &nbsp; FList := v is TCustomListBox;<br>&nbsp; &nbsp; &nbsp; FGrid := v is TDrawGrid;<br>&nbsp; &nbsp; &nbsp; FCombo := v is TCustomComboBox;<br>&nbsp; &nbsp; &nbsp; FButton := v is TButtonControl;<br>&nbsp; &nbsp; &nbsp; FRadio := v is TRadioGroup;<br><br>{ &nbsp; &nbsp; &nbsp;FEdit:=HasProperty(v,'Text');<br>&nbsp; &nbsp; &nbsp; FList:=HasProperty(v,'Items');<br>&nbsp; &nbsp; &nbsp; FGrid:=HasProperty(v,'ColCount') or HasProperty(v,'RowCount');<br>&nbsp; &nbsp; &nbsp; FButton:=v is TButtonControl;<br>}<br>&nbsp; &nbsp; &nbsp; case Msg.wParam of<br>&nbsp; &nbsp; &nbsp; &nbsp; VK_UP: Handled:=MoveUpSide(v, Msg.wParam);<br>&nbsp; &nbsp; &nbsp; &nbsp; VK_DOWN: Handled:=MoveDownSide(v, Msg.wParam);<br>&nbsp; &nbsp; &nbsp; &nbsp; VK_LEFT: Handled:=MoveLeftSide(v, Msg.wParam);<br>&nbsp; &nbsp; &nbsp; &nbsp; VK_RIGHT: Handled:=MoveRightSide(v, Msg.wParam);<br>&nbsp; &nbsp; &nbsp; &nbsp; VK_RETURN: Handled:=MoveNextSide(v, Msg.wParam);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; if assigned(FOwnerKeyEvents) then FOwnerKeyEvents(Msg,handled);<br><br>end;<br><br>function TQuickKey.MoveUpSide(Sender: TWinControl; Key: word):boolean;<br>var<br>&nbsp; v: boolean;<br>begin<br>&nbsp; v:=false;<br>&nbsp; if FList then<br>&nbsp; &nbsp; if moListDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; if (Sender as TCustomListBox).ItemIndex=0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; else<br>&nbsp; else if FCombo then<br>&nbsp; &nbsp; if moComboDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; &nbsp;if (Sender as TCustomComboBox).ItemIndex=0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v:=true<br>&nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; else<br>&nbsp; else if FButton then<br>&nbsp; &nbsp; if moButtonDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; else<br>&nbsp; else if FRadio then<br>&nbsp; &nbsp; if moRadioDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; if (Sender as TRadioGroup).ItemIndex = 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; else<br>&nbsp; else if FEdit then<br>&nbsp; &nbsp; if moEditDeliver in FOptions then<br>&nbsp; &nbsp; if CanEnterKey(Sender) then<br>&nbsp; &nbsp; &nbsp; &nbsp;if HasProperty(Sender, 'Lines') then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (Sender as TCustomEdit).SelStart<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +(Sender as TCustomEdit).SelLength=0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; v:=true<br>&nbsp; &nbsp; else<br>&nbsp; else if FGrid then<br>&nbsp; &nbsp; if moGridDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; if (not CanEnterKey(Sender))<br>&nbsp; &nbsp; &nbsp; and ((Sender as TDrawGrid).row&lt;=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetPropertyValue(Sender,'FixedRows')<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )<br>&nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; v:=true;<br>&nbsp; if v then<br>&nbsp; begin<br>&nbsp; &nbsp; GetControl(Sender,1);<br>&nbsp; end;<br>&nbsp; result:=v;<br>end;<br><br>function TQuickKey.MoveDownSide(Sender: TWinControl;<br>&nbsp; Key: word):boolean;<br>var<br>&nbsp; v: Boolean;<br>begin<br>&nbsp; v:=false;<br>&nbsp; if FList then<br>&nbsp; &nbsp; if moListDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; if (Sender as TCustomListBox).ItemIndex=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(Sender as TCustomListBox).Items.Count-1<br>&nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; else<br>&nbsp; else if FCombo then<br>&nbsp; &nbsp; if moComboDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; &nbsp;if (Sender as TCustomComboBox).ItemIndex=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (Sender as TCustomComboBox).Items.Count-1<br>&nbsp; &nbsp; &nbsp; &nbsp;then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v:=true<br>&nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; else<br>&nbsp; else if FButton then<br>&nbsp; &nbsp; if moButtonDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; else<br>&nbsp; else if FRadio then<br>&nbsp; &nbsp; if moRadioDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; if (Sender as TRadioGroup).ItemIndex =<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(Sender as TRadioGroup).Items.Count-1<br>&nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; else<br>&nbsp; else if FEdit then<br>&nbsp; &nbsp; if moEditDeliver in FOptions then<br>&nbsp; &nbsp; if CanEnterKey(Sender) then<br>&nbsp; &nbsp; &nbsp; &nbsp;if HasProperty(Sender, 'Lines') then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (Sender as TCustomEdit).SelStart<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+(Sender as TCustomEdit).SelLength&gt;=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;length((Sender as TCustomEdit).text)-1<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; v:=true<br>&nbsp; &nbsp; else<br>&nbsp; else if FGrid then<br>&nbsp; &nbsp; if moGridDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; if (not CanEnterKey(Sender))<br>&nbsp; &nbsp; &nbsp; and ((Sender as TDrawGrid).Row&gt;=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetPropertyValue(Sender, 'RowCount')-1)<br>&nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; v:=true;<br><br>&nbsp; if v then<br>&nbsp; begin<br>&nbsp; &nbsp; GetControl(Sender,3);<br>&nbsp; end;<br>&nbsp; result:=v;<br>end;<br><br>function TQuickKey.MoveLeftSide(Sender: TWinControl;<br>&nbsp; key: word):boolean;<br>var<br>&nbsp; v: boolean;<br>begin<br>&nbsp; v:=false;<br>&nbsp; if FList then<br>&nbsp; &nbsp; if moListDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; if (Sender as TCustomListBox).ItemIndex= 0<br>// &nbsp; &nbsp; &nbsp; &nbsp; (Sender as TCustomListBox).Items.Count-1<br>&nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; else<br>&nbsp; else if FCombo then<br>&nbsp; &nbsp; if moComboDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; &nbsp;if CanEnterKey(Sender) &nbsp;then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (Sender as TCustomCombobox).selstart<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +(Sender as TCustomComboBox).SelLength = 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v:=true<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; else<br>&nbsp; else if FButton then<br>&nbsp; &nbsp; if moButtonDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; else<br>&nbsp; else if FRadio then<br>&nbsp; &nbsp; if moRadioDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; if (Sender as TRadioGroup).ItemIndex = 0<br>// &nbsp; &nbsp; &nbsp; &nbsp; (Sender as TRadioGroup).Items.Count-1<br>&nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; else<br>&nbsp; else if FEdit then<br>&nbsp; &nbsp; if moEditDeliver in FOptions then<br>&nbsp; &nbsp; if CanEnterKey(Sender) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (Sender as TCustomEdit).SelStart<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+(Sender as TCustomEdit).SelLength=0<br>// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; length((Sender as TCustomEdit).text)-1<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; v:=true<br>&nbsp; &nbsp; else<br>&nbsp; else if FGrid then<br>&nbsp; &nbsp; if moGridDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; if (not CanEnterKey(Sender))<br>&nbsp; &nbsp; &nbsp; and ((Sender as TDrawGrid).Col&lt;=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetPropertyValue(Sender,'FixedCols'))<br>&nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; v:=true;<br>&nbsp; if v then<br>&nbsp; begin<br>&nbsp; &nbsp; GetControl(Sender,0);<br>&nbsp; end;<br>&nbsp; result:=v;<br>end;<br><br>function TQuickKey.MoveRightSide(Sender: TWinControl;<br>&nbsp; Key: word):boolean;<br>var<br>&nbsp; v: boolean;<br>begin<br>&nbsp; v:=false;<br>&nbsp; if FList then<br>&nbsp; &nbsp; if moListDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; if (Sender as TCustomListBox).ItemIndex=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(Sender as TCustomListBox).Items.Count-1<br>&nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; else<br>&nbsp; else if FCombo then<br>&nbsp; &nbsp; if moComboDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; &nbsp;if CanEnterKey(Sender) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (Sender as TCustomComboBox).SelStart<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+(Sender as TCustomComboBox).SelLength&gt;=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; length((Sender as TComboBox).text)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v:=true<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; else<br>&nbsp; else if FButton then<br>&nbsp; &nbsp; if moButtonDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; else<br>&nbsp; else if FRadio then<br>&nbsp; &nbsp; if moRadioDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; if (Sender as TRadioGroup).ItemIndex =<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(Sender as TRadioGroup).Items.Count-1<br>&nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; else<br>&nbsp; else if FEdit then<br>&nbsp; &nbsp; if moEditDeliver in FOptions then<br>&nbsp; &nbsp; if CanEnterKey(Sender) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (Sender as TCustomEdit).SelStart<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +(Sender as TCustomEdit).SelLength&gt;=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;length((Sender as TCustomEdit).text)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; v:=true<br>&nbsp; &nbsp; else<br>&nbsp; else if FGrid then<br>&nbsp; &nbsp; if moGridDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; if (not CanEnterKey(Sender))<br>&nbsp; &nbsp; &nbsp; and ((Sender as TDrawGrid).col&gt;=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetPropertyValue(Sender,'ColCount')-1)<br>&nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; v:=true;<br>&nbsp; if v then<br>&nbsp; begin<br>&nbsp; &nbsp; GetControl(Sender,2);<br>&nbsp; end;<br>&nbsp; result:=v;<br>end;<br><br>function TQuickKey.MoveNextSide(Sender: TwinControl;<br>&nbsp; Key: word):boolean;<br>var<br>&nbsp; v: boolean;<br>begin<br>&nbsp; v:=false;<br>&nbsp; if FList then<br>&nbsp; &nbsp; if moListDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; if (Sender as TCustomListBox).ItemIndex=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(Sender as TCustomListBox).Items.Count-1<br>&nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; else<br>&nbsp; else if FCombo then<br>&nbsp; &nbsp; if moComboDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; &nbsp;if CanEnterKey(Sender) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (Sender as TCustomComboBox).SelStart<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+(Sender as TCustomComboBox).SelLength&gt;=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; length((Sender as TComboBox).text)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v:=true<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; else<br>&nbsp; else if FRadio then<br>&nbsp; &nbsp; if moRadioDeliver in FOptions then<br>&nbsp; &nbsp; &nbsp; if (Sender as TRadioGroup).ItemIndex =<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(Sender as TRadioGroup).Items.Count-1<br>&nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; else<br>&nbsp; else if FEdit then<br>&nbsp; &nbsp; if CanEnterKey(Sender) then<br>&nbsp; &nbsp; &nbsp; &nbsp;if HasProperty(Sender, 'Lines') then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (Sender as TCustomEdit).SelStart<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+(Sender as TCustomEdit).SelLength&gt;=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;length((Sender as TCustomEdit).text)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v:=true<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; v:=true;<br>&nbsp; if v then<br>&nbsp; begin<br>// &nbsp; &nbsp;GetControl(Sender,4);<br>&nbsp; &nbsp; (Sender.Owner as TForm).Perform(WM_NEXTDLGCTL,0,0);<br>&nbsp; end;<br>&nbsp; result:=v;<br>end;<br><br>function TQuickKey.CanEnterKey(Sender: TWinControl): boolean;<br>begin<br>&nbsp; &nbsp; &nbsp;if hidecaret(0) then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showcaret(0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result:=true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if HasProperty(Sender,'ReadOnly')<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and (not TestProperty(Sender,'ReadOnly',0))<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result:=false;<br>&nbsp; &nbsp; &nbsp;end<br>&nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp;result:=false;<br>end;<br><br>function TQuickKey.HasProperty(Sender:TObject; AProperty: string):boolean;<br>begin<br>&nbsp; &nbsp; &nbsp;result:=(GetPropInfo(Sender.ClassInfo, AProperty)&lt;&gt;nil);<br>end;<br><br>function TQuickKey.TestProperty(Sender:TObject; AProperty: string;<br>&nbsp; &nbsp;Value: integer): boolean;<br>var<br>&nbsp; &nbsp;T:pPropInfo;<br>begin<br>&nbsp; &nbsp;T:=GetPropInfo(Sender.ClassInfo, AProperty);<br>&nbsp; &nbsp;result:=(GetOrdProp(Sender,T) = Value);<br>end;<br><br>procedure TQuickKey.GetControl(Sender:TWinControl;Direct:integer);<br>var<br>&nbsp; i: integer;<br>&nbsp; scs: TRect;<br>&nbsp; sc1,sc2: TRect;<br>&nbsp; wc: TWinControl ;<br>&nbsp; f:TForm;<br>begin<br>&nbsp; wc:=nil;<br>&nbsp; f:= Sender.Owner as TForm;<br>{ &nbsp;scs := Sender.BoundsRect;<br>&nbsp; scs.TopLeft :=<br>&nbsp; &nbsp; (Sender.Parent as TWinControl).ClientToScreen(sc1.TopLeft);<br>&nbsp; scs.BottomRight :=<br>&nbsp; &nbsp; (Sender.Parent as TWinControl).ClientToScreen(sc1.BottomRight);<br>&nbsp; }<br><br>&nbsp; scs := Sender.ClientRect;<br>&nbsp; scs.TopLeft :=<br>&nbsp; &nbsp; (Sender as TWinControl).ClientToScreen(scs.TopLeft);<br>&nbsp; scs.BottomRight :=<br>&nbsp; &nbsp; (Sender as TWinControl).ClientToScreen(scs.BottomRight);<br>&nbsp; { &nbsp;}<br>&nbsp; case Direct of<br>&nbsp; &nbsp; 0:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; scs.Right:=scs.Left-1;<br>&nbsp; &nbsp; &nbsp; &nbsp; scs.Left:=-3000;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; 1:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; scs.Bottom:=scs.Top-1;<br>&nbsp; &nbsp; &nbsp; &nbsp; scs.Top:=-3000;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; 2:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; scs.Left:=scs.Right+1;<br>&nbsp; &nbsp; &nbsp; &nbsp; scs.Right:=3000;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; 3:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; scs.Top:=scs.bottom+1;<br>&nbsp; &nbsp; &nbsp; &nbsp; scs.Bottom:=3000;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; for i:= 0 to f.ComponentCount-1 do<br>&nbsp; begin<br>&nbsp; &nbsp; if (f.Components &lt;&gt; Sender)<br>{ &nbsp; &nbsp;and (<br>&nbsp; &nbsp; &nbsp; &nbsp; (f.Components is TWinControl) and<br>&nbsp; &nbsp; &nbsp; &nbsp; (HasProperty(f.Components,'Text') or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HasProperty(f.Components,'Items') or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HasProperty(f.Components,'ColCount')<br>&nbsp; &nbsp; &nbsp; ) )}<br>&nbsp; &nbsp; and (f.Components is TWinControl)<br>&nbsp; &nbsp; and (<br>&nbsp; &nbsp; (not HasProperty(f.Components,'ControlCount'))<br>&nbsp; &nbsp; or (<br>&nbsp; &nbsp; &nbsp;HasProperty(f.components,'ControlCount')<br>&nbsp; &nbsp; &nbsp;and TestProperty(f.Components,'ControlCount',0)<br>&nbsp; &nbsp; &nbsp;)<br>&nbsp; &nbsp; )<br>&nbsp; &nbsp; and (f.Components as TWinControl).CanFocus<br>&nbsp; &nbsp; then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; sc1:=(f.components as TWinControl).BoundsRect;<br>&nbsp; &nbsp; &nbsp; sc1.TopLeft:=<br>&nbsp; &nbsp; &nbsp; &nbsp;((f.Components as TWinControl).Parent as TWinControl).ClientToScreen(sc1.TopLeft);<br>&nbsp; &nbsp; &nbsp; sc1.BottomRight:=<br>&nbsp; &nbsp; &nbsp; &nbsp; ((f.Components as TWinControl).Parent as TWinControl).ClientToScreen(sc1.BottomRight);<br>&nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; sc1:=(f.components as TWinControl).ClientRect;<br>&nbsp; &nbsp; &nbsp; sc1.TopLeft:=<br>&nbsp; &nbsp; &nbsp; &nbsp;(f.Components as TWinControl).ClientToScreen(sc1.TopLeft);<br>&nbsp; &nbsp; &nbsp; sc1.BottomRight:=<br>&nbsp; &nbsp; &nbsp; &nbsp; (f.Components as TWinControl).ClientToScreen(sc1.BottomRight);<br>&nbsp; &nbsp; &nbsp; {}<br>&nbsp; &nbsp; &nbsp; if IntersectRect(sc2,scs,sc1) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wc:=f.Components as TWinControl;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case Direct of<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0: scs.Left:=sc2.Right+1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1: scs.Top:=sc2.Bottom+1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2: scs.Right:=sc2.Left-1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3: scs.Bottom:=sc2.Top-1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (scs.Top&gt;scs.Bottom) or (scs.Left&gt;scs.Right) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; &nbsp; if wc&lt;&gt;nil then<br>&nbsp; &nbsp; &nbsp; &nbsp;postmessage(f.Handle,WM_NEXTDLGCTL,wc.Handle,1)<br>&nbsp; &nbsp; else if Direct&lt;=1 then<br>&nbsp; &nbsp; &nbsp; postmessage(f.handle,WM_NEXTDLGCTL,1,0)<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; postmessage(f.handle,WM_NEXTDLGCTL,0,0);<br><br>end;<br><br>function TQuickKey.GetPropertyValue(Sender:TObject; AProperty:string):integer;<br>var<br>&nbsp; T:pPropInfo;<br>begin<br>&nbsp; T:=GetPropInfo(Sender.ClassInfo,AProperty);<br>&nbsp; if T&lt;&gt;nil then<br>&nbsp; &nbsp; result:=GetOrdProp(Sender,T)<br>&nbsp; else<br>&nbsp; &nbsp; result:=-1;<br>end;<br><br>end.
 
天哪,怎么用这么一大堆,看看form的selectnext,selectprev吧.
 
将所有的EditKeyDown指向一个KeyDown事件然后写入下列代码,同时<br>Form1.KeyPreview设为True;<br><br>procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;<br>&nbsp;Shift: TShiftState);<br>begin<br>&nbsp; case Key of<br>&nbsp; &nbsp;VK_LEFT: begin<br>&nbsp; &nbsp; &nbsp;if (Sender as TEdit).Selstart&lt;&gt;0 then Exit;<br>&nbsp; &nbsp; &nbsp;Perform(WM_NEXTDLGCTL,1,0);<br>&nbsp; &nbsp; &nbsp;if (ActiveControl is TEdit) then<br>&nbsp; &nbsp; &nbsp; (ActiveControl as Tedit).selstart :=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(ActiveControl as Tedit).MaxLength - 1;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp;VK_RIGHT: begin<br>&nbsp; &nbsp; &nbsp;if (Sender as TEdit).Selstart&lt;&gt;(Sender as TEdit).GetTextLen<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; then Exit;<br>&nbsp; &nbsp; &nbsp;Perform(WM_NEXTDLGCTL,0,0);<br>&nbsp; &nbsp; &nbsp;if (ActiveControl is TEdit) then<br>&nbsp; &nbsp; &nbsp; (ActiveControl as Tedit).selstart :=0;<br>&nbsp; &nbsp; end;<br>&nbsp; end; &nbsp; &nbsp; &nbsp; <br>end;
 
请注意:下一个Edit的TabOrder值要为上一个Edit的TabOrder的下一个数.<br>
 
同意 Fudei 的方法,但不是在Edit1的Onkeydown事件里,应该在form的Onkeydown事件里,且form的keyprew属性设为true.
 
我说的是在捕获方向键后,控制Tedit内的光标的移动.<br>例如:edit1中原有字符串'我们',当edit1获得输入焦点<br>时,按向右的方向键,则光标由'我'的前面变为'们'的前面,<br>再按向右的方向键,则光标由'们'的前面变为'们'的后面,<br>再按向右的方向键,跳至下一个输入焦点的Tedit.<br>
 
To rice: 你试过吗我那代码就是你所说的用途呀!<br>
 
thans,i get it!!!
 
多人接受答案了。
 
顶部