在查询时有时不仅要日期还要有起始时间,一般TDateTimePicker要么修改日期,要么修改时间,用个小小技巧就能解决
新建一个TDateTimePicker控件DateTimePicker1并设置其属性
with DateTimePicker1 do begin
Format:=‘yyyy-MM-dd HH:mm:ss';
Kind:=dtkDate;
DateMode:=dmComboBox;
end
双击DateTimePicker1的事件ContextPopup修改事件处理器
procedure TFormNote.DateTimePicker1ContextPopup(Sender: TObject;
MousePos: TPoint; var Handled: Boolean);
begin
with (Sender as TDateTimePicker) do begin
if Kind=dtkDate then begin
Kind:=dtkTime;
DateMode:=dmUpDown;
end else begin
Kind:=dtkDate;
DateMode:=dmComboBox;
end;
end;
end;
这样默认为下拉框设置日期,如果要设置时间,按一下右键即可用上下按钮设置时间,再按右键可以回到日期设置状态