L
lijucheng8
Unregistered / Unconfirmed
GUEST, unregistred user!
请教:DatetimePicker 显示为 年/月/日, 按Enter键自动跳转,到日后 焦点移动到其他控件 ,为什么要这样:当输入大量数据时,客户觉得按TAB键麻烦,同理:当有二个datetimepicker时,每次得到焦点,希望光标落在YYYY上的。以下是程序, 原理就是当在日上按回车时,日改变,这样就跳到下一目标。调了一天都调不好procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin if key=vk_return then begin if (ActiveControl is Tdatetimepicker) then begin IsDayChange:=false;// d:=picker1.Date; //先取得日期 keybd_event(vk_up,0,0,0); keybd_event(vk_up,0,KEYEVENTF_KEYUP,0); keybd_event(vk_down,0,0,0); keybd_event(vk_down,0,KEYEVENTF_KEYUP,0); //上下移动,值不会变,但应该会引发picker1的change 事件,但总是不能捕捉到 if IsDayChange then keybd_event(vk_tab,0,0,0) else keybd_event(vk_right,0,0,0); end else SendMessage(Self.Handle, WM_NEXTDLGCTL, 0, 0); end;end;procedure TForm1.Picker1Change(Sender: TObject);begin if d<>picker1.Date then IsDayChange:=true;end; 原理就是当在日上按回车时,日改变,这样就跳到下一目标,