将焦点返回到Delphi TDateTimePicker控件的第一部分 [英] Returning focus to first part of Delphi TDateTimePicker control

查看:204
本文介绍了将焦点返回到Delphi TDateTimePicker控件的第一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

焦点离开TDateTimerPicker控件,然后在稍后返回时,该控件会记住哪个部分(日,月或年)具有焦点.焦点返回到该部分.

After the focus leaves a TDateTimerPicker control and then at a later time returns to it, the control remembers which part (day, month or year) had the focus. Focus is returned to that part.

如何将焦点强制回到控件的第一个?

How can I force the focus back to the first per of the control?

推荐答案

要强制控件忘记哪个部分具有焦点,可以更改DateFormat,然后再次将其更改.因此,如果将其设置为dfShort,则将其设置为dfLong,然后再返回到dfShort.

To force the control to forget which part had the focus you can change the DateFormat and then change it back again. So if it is set to dfShort set it to dfLong and then back to dfShort.

诀窍不是在通过OnEnter事件返回焦点之后执行此操作,而是在返回焦点之前执行此操作.

The trick is not to do this after the focus returns via the OnEnter event, but to do it before the focus is returned.

所以最好的选择是在OnExit事件中.

So the best place to do this is in the OnExit event.

procedure TForm1.DateTimePicker1Exit(Sender: TObject);
begin

  DateTimePicker1.DateFormat := dfLong;
  DateTimePicker1.DateFormat := dfShort;

end;

这篇关于将焦点返回到Delphi TDateTimePicker控件的第一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆