Show invalid dates disabled in TDateTimePicker

I use TDateTimePicker to let the user select a day (either manually or by pressing buttons to go forward or backward one day). Then the user will see the journal entries for that particular day.

Management works fine, but I want to restrict the user between [OLDEST-DAY-IN-LOG] and [TODAY], because these are restrictions on the date when there is data.

I set MinDate and MaxDate to TDateTimePicker and it works fine. Selecting a date outside the valid range does nothing.

My question is whether invalid dates can be displayed in gray. In the attached image, the selected date is 01/04, and today is 02/04. I would like to see 03/04 (and later) disconnected. Ideally, as “30” and “31”, you see an image that is the last day of March.

Is it possible? Use Delphi 7 if relevant.

TDateTimePicker control in Delphi

+4
source share
2 answers

, normal and bold. TYearBoldManager .

30 31 1 1,2,3,4

: Delphi5 XP/3

minDate = 2015/03/30 maxDate = 2015/04/04

bold

procedure TForm1.FormCreate(Sender: TObject);
begin
   MonthCalendar1.CalColors.MonthBackColor :=  $6A7678;
   MonthCalendar1.CalColors.TextColor := $4D5858;

   FYearBoldManager := TYearBoldManager.Create;
   FYearBoldManager.MakeBold(3, 30);
   FYearBoldManager.MakeBold(3, 31);
   FYearBoldManager.MakeBold(4, 1);
   FYearBoldManager.MakeBold(4, 2);
   FYearBoldManager.MakeBold(4, 3);
   FYearBoldManager.MakeBold(4, 4);
   ...
end;

, . .

enter image description here

enter image description here

4 , MonthCalendarDemo

:

MonthCalendarDemo.dpr

program MonthCalendarDemo;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  UMonthBoldStorage in 'UMonthBoldStorage.pas';

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

UMonthBoldStorage.pas .


?

enter image description here

.

TDateTimePicker

a TMonthCalendar a TComboBox

:

  • min-maxDate
  • days without logfile.
  • .
  • .
  • , ( 25, ).
  • , ( , , . : 20 22).

enter image description here

  • TComboBox down-arrow ENTER .

enter image description here

enter image description here

  • , , , .

enter image description here

procedure TForm1.MonthCalendar1DblClick(Sender: TObject);
var
   year, month, day : Word;
begin
    DecodeDate(MonthCalendar1.Date,Year, Month, Day);
    if FYearBoldManager.GetDayStatus(month, day) then begin
       if ValidDate then MonthCalendar1.Visible:=False;
    end;
end;

procedure TForm1.MonthCalendar1Click(Sender: TObject);
var
   year, month, day : Word;
begin
   DecodeDate(MonthCalendar1.Date,Year, Month, Day);
   if FYearBoldManager.GetDayStatus(month, day) then begin
      lastValidDate := MonthCalendar1.Date;
      ValidDate:=True;
   end else begin
      MonthCalendar1.Date := lastValidDate;
      ValidDate:=False;
   end;
end;

function TForm1.getComboBoxText(var validText:AnsiString):Boolean;
var
actText :AnsiString;

begin
    if ComboBox1.Text = '' then  actText := validText else actText := ComboBox1.Text;
    Try
    MonthCalendar1.Date :=  StrToDateTime(Copy(actText,1,10));
    if actText <> validText then validText := actText;
    lastValidDate := MonthCalendar1.Date;
    ValidDate:=True;
    Result := True;
    except
      Result := False;
    end;
end;

procedure TForm1.ComboBox1Click(Sender: TObject);
begin
     if getComboBoxText(validText) then MonthCalendar1.Visible:=True;
end;

procedure TForm1.ComboBox1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
     if getComboBoxText(validText) then MonthCalendar1.Visible:=True;
end;
+1

All Articles