如何让datetimepicker中的框中不显示任何日期呀?
我想通过这个方法来表示日期尚未输入或日期求知
谢谢!

解决方案 »

  1.   

    ...Show Week Numbers in a TDateTimePicker?
    在DateTimePicker中显示星期?
     
    uses
      CommCtrl;type
      THackCommonCalendar = class(TCommonCalendar);  {...}procedure TForm1.DateTimePicker1DropDown(Sender: TObject);
    var
      Style: Integer;
      ReqRect: TRect;
      MaxTodayWidth: Integer;
    begin
      with THackCommonCalendar(Sender as TDateTimePicker) do
      begin
        // set style to include week numbers 
        Style := GetWindowLong(CalendarHandle, GWL_STYLE);
        SetWindowLong(CalendarHandle, GWL_STYLE, Style or MCS_WEEKNUMBERS);
        FillChar(ReqRect, SizeOf(TRect), 0);
        // get required rect 
        Win32Check(MonthCal_GetMinReqRect(CalendarHandle, ReqRect));
        // get max today string width 
        MaxTodayWidth := MonthCal_GetMaxTodayWidth(CalendarHandle); 
        // adjust rect width to fit today string 
        if MaxTodayWidth > ReqRect.Right then 
          ReqRect.Right := MaxTodayWidth;
        // set new height & width 
        SetWindowPos(CalendarHandle, 0, 0, 0, ReqRect.Right, ReqRect.Bottom, 
          SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOZORDER); 
      end; 
    end;
    ********************************
    如何实现再开始的时候,让DateTimePicker如下面一样,提醒用户选择时间?
     
    {
     Use the DateTime_SetFormat API macro (put CommCtrl in the uses clause) to set
     the date to blank or a message. Then in the DateTimePicker OnCloseUp event handler set the format to what you
     want when a date has been selected, and the DTP will show the selected date. Attach an OnClick handler if you want it to open when you
     click on the edit control.
    }uses
      CommCtrl;var
      FDTMDateEmpty: Boolean;procedure TForm1.FormCreate(Sender: TObject);
    begin
      DateTime_SetFormat(DateTimePicker1.Handle,  '''Choose a date''');
      FDTMDateEmpty := True;
    end;procedure TForm1.DateTimePicker1CloseUp(Sender: TObject);
    begin
      DateTime_SetFormat(DateTimePicker1.Handle,  PChar('dd.MM.yy'));
    end;procedure TForm1.DateTimePicker1Click(Sender: TObject);
    begin
      if FDTMDateEmpty then
      begin
        DateTimePicker1.Perform(WM_KEYDOWN, VK_F4, 0);
        DateTimePicker1.Perform(WM_KEYUP, VK_F4, 0);
      end;
    end;procedure TForm1.DateTimePicker1Change(Sender: TObject);
    begin
      FDTMDateEmpty := False;
    end;
      

  2.   

    hangguojun(布丁) 正解放一个TEdit到TDateTimePicker前面,
    在自己理想的条件,才让TDateTimePicker的时间显示在TEdit里面
    不过有一个问题,TDateTimePicker懂得控制时间格式
    如果你的是多语言版本,记得格式化一下时间再显示。