正如已经在 cmets 中提到的,答案只有样式 normal and bold 可以使用。使用TYearBoldManager,您可以实现它。
仅设置为 3 月 30,31 日和 4 月 1,2,3,4 日
测试:Delphi5 on win 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;
然后您应该更改颜色值以获得最佳对比度。这里只是一个建议。
测试有4个文件here , 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是怎么做的。
这里有什么区别?
专家们已经认识到了。
向右TDateTimePicker
左边是TMonthCalendar 和TComboBox
优势:
- 不需要 min-maxDate
- 可以有
days without logfile。
- 完全控制日历。
- 粗体字好用
- 可以看到您点击的位置(查看
25 的漂亮虚线边框。但对日历没有影响)。
- 点击错误的日期不会消失。(可以随意点击,只有双击粗体时日历才会消失。这里:第 20 天和第 22 天)。
- 可以在
TComboBox 内部或down-arrow 上单击,或者当重点点击时ENTER 打开日历并通过日志文件将您带到最后一个日期。
- 您可以从那里轻松地使用箭头键查看有日志文件的月份和日期。
所有描述都可以通过几行附加代码来完成
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;