Jus*_*tMe 9 delphi delphi-2010
我有我的自定义类扩展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;
Run Code Online (Sandbox Code Playgroud)
在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;
Run Code Online (Sandbox Code Playgroud)
但它没有将焦点转移到下一个控制.我试过了
if Key = VK_RETURN then
Key := VK_TAB;
Run Code Online (Sandbox Code Playgroud)
但它也没有用.我错过了什么?
Ond*_*lle 12
SelectNext选择下一个兄弟儿童控制,即.你需要在编辑的父母上调用它:
type
THackWinControl = class(TWinControl);
if Key = VK_RETURN then
if Assigned(Parent) then
THackWinControl(Parent).SelectNext(Self, True, False);
Run Code Online (Sandbox Code Playgroud)
这是PostMessage方法(使用Messages)记录:)
procedure TMyEdit.KeyUp(var Key: Word; Shift: TShiftState);
begin
inherited;
if FocusNextOnExnter then
if Key = VK_RETURN then begin
PostMessage(GetParentForm(Self).Handle, wm_NextDlgCtl, Ord((ssShift in Shift)), 0);
Key := 0;
end;
end;
Run Code Online (Sandbox Code Playgroud)
小智 5
procedure TMyEdit.KeyUp(var Key: Word; Shift: TShiftState);
begin
inherited;
if FocusNextOnExnter and Focused and (Key = VK_RETURN) then
begin
Perform(CM_DIALOGKEY, VK_TAB, 0);
Key := 0;
end;
end;
Run Code Online (Sandbox Code Playgroud)