在TDateTimePicker上设置日期下拉

Mat*_*hew 1 delphi calendar date datetimepicker

我在Delphi 6表单上有一个DateTimePicker,默认日期为30/12/1899.我希望用户能够点击它或打开下拉日历并选择当前日期.使用OnClick过程:

DateTimePicker.Date:=日期

将可编辑部分中的日期设置为用户单击日期或日历下拉按钮时的日期,但不会强制日历自动选择今天的日期.如果我在DateTimePicker的OnDropDown过程中使用此代码,结果是相同的.

我是否需要使用此帖中的内容来操作日历?还是有一个我错过的简单财产?

谢谢马特

kob*_*bik 5

您可以直接通过更新月份日历窗口MonthCal_SetCurSel.
像这样的东西(我把"默认"逻辑留给你):

uses Commctrl;

type TDateTimePickerAccess = class(TDateTimePicker);

procedure TForm1.DateTimePicker1DropDown(Sender: TObject);
var
  ST: TSystemTime;
  CalendarHandle: HWND;
begin
  DateTimePicker1.Date := Date;
  DateTimeToSystemTime(Date, ST);
  CalendarHandle := TDateTimePickerAccess(DateTimePicker1).GetCalendarHandle;
  MonthCal_SetCurSel(CalendarHandle, ST);
end;
Run Code Online (Sandbox Code Playgroud)

我个人会将默认日期设置为默认日期(Date).