如何以编程方式在Delphi的TDateTimePicker日历中标记日期?

前端之家收集整理的这篇文章主要介绍了如何以编程方式在Delphi的TDateTimePicker日历中标记日期?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
用户点击DateTimePicker,设置为下拉日历时,我希望各种日期(通过我创建的代码选择)以某种方式突出显示彩色背景,粗体字体,彩色字体,无关紧要.我只想要标记某些日期. ……我怎么办?

谢谢,一如既往!

解决方法

是的,你可以这样做.首先,您必须初始化控件:
const
  DTM_GETMCSTYLE = DTM_FIRST + 12;
  DTM_SETMCSTYLE = DTM_FIRST + 11;
...
SendMessage(DateTimePicker1.Handle,DTM_SETMCSTYLE,SendMessage(DateTimePicker1.Handle,DTM_GETMCSTYLE,0) or MCS_DAYSTATE);

(使用CommCtrl).

然后,您只需响应MCN_GETDAYSTATE通知.您可以创建自己的TDateTimePicker后代,也可以使用“拦截器类”.

type
  TDateTimePicker = class(ComCtrls.TDateTimePicker)    
  protected
    procedure WndProc(var Message: TMessage); override;
  end;

  ...

procedure TDateTimePicker.WndProc(var Message: TMessage);
var
  i: integer;
begin
  inherited;
  case Message.Msg of
    WM_NOTIFY:
      with PNMDayState(Message.LParam)^ do
        if nmhdr.code = MCN_GETDAYSTATE then
        begin
          // The first visible day is SystemTimeToDateTime(stStart);
          // cDayState is probably three,because most often three months are
          // visible at the same time. Of course,the second of these is the
          // 'currently displayed month'.
          // Each month is represented by a DWORD (32-bit unsigned integer)
          // bitfield,where 0 means not bold,and 1 means bold.
          // For instance,the following code will select all days:
          for i := 0 to cDayState - 1 do
            PMonthDayState(Cardinal(prgDayState) + i*sizeof(TMonthDayState))^ := $FFFFFFFF;
        end;
  end;
end;

另一个例子:假设当前显示包含三个月,并且您只想选择“当前显示月份”中的天数,即中间月份.假设您希望每隔三天选择一次,从选定日期开始.

然后你想使用位域

Month  Bitfield
0      00000000000000000000000000000000
1      01001001001001001001001001001001
2      00000000000000000000000000000000

哪个是

Month  Bitfield
0      $00000000
1      $49249249
2      $00000000

十六进制.所以你也是

for i := 0 to cDayState - 1 do
  if i = 1 then
    PMonthDayState(cardinal(prgDayState) + i*sizeof(TMonthDayState))^ := $49249249
  else
    PMonthDayState(cardinal(prgDayState) + i*sizeof(TMonthDayState))^ := $00000000;

Screenshot http://privat.rejbrand.se/datetimepick.png

原文链接:https://www.f2er.com/delphi/101658.html

猜你在找的Delphi相关文章