datetimepicker如果在获得焦点的时候自动定位到日期上,TDateTimePicker自动焦点定位到年,TDateTimePicker自动焦点定位到月,TDateTimePicker自动焦点定位到日
定位到月上
if key=vk_return then
begin
DTP1.SetFocus;
SendMessage(DTP1.Handle,WM_KEYDOWN,39,0);
end;
定位到日上
if key=vk_return then
begin
DTP1.SetFocus;
SendMessage(DTP1.Handle,WM_KEYDOWN,39,0);
SendMessage(DTP1.Handle,WM_KEYDOWN,39,0);
end;
DTP1.SetFocus;
SendMessage(DTP1.Handle,WM_KEYDOWN,VK_RIGHT,0);
SendMessage(DTP1.Handle,WM_KEYDOWN,VK_RIGHT,0)
39是VK_RIGHT的虚拟键值。。通用的,就用上面这个,程序容易理解,就是把焦点移动到dataetimepicker上后,模拟光标vk_right被按下。