我有我的自定义类扩展TEdit:
TMyTextEdit = class (TEdit) private fFocusNextOnEnter: Boolean; public procedure KeyUp(var Key: Word; Shift :TShiftState); override; published property FocusNextOnExnter: Boolean read fFocusNextOnEnter write fFocusNextOnEnter default false; end;
在KeyUp过程中我做:
procedure TMyTextEdit.KeyUp(var Key: Word; Shift: TShiftState); begin inherited; if FocusNextOnExnter then if Key = VK_RETURN then SelectNext(Self as TWinControl,True,false); end;
但它并没有转移到下一个控件的焦点.我尝试过了
if Key = VK_RETURN then Key := VK_TAB;
但它也不工作.我失踪了什么
解决方法
SelectNext
选择下一个兄弟姐妹控制,即.您需要在编辑的父母上调用它:
type THackWinControl = class(TWinControl); if Key = VK_RETURN then if Assigned(Parent) then THackWinControl(Parent).SelectNext(Self,False);