Delphi 的 DateTimePicker 組件有一個CalColors屬性,能夠設置 DropDown 打開的日曆節目的風格。但若是不使用 Delphi 自帶的 Style,在這裏設置屬性看不到指望的效果。api
1 uses 2 Winapi.CommCtrl, 3 Vcl.Styles, 4 Vcl.Themes, 5 uxTheme; 6 7 Procedure SetVclStylesColorsCalendar( DateTimePicker: TDateTimePicker); 8 Var 9 LTextColor, LBackColor : TColor; 10 begin 11 uxTheme.SetWindowTheme(DateTimePicker.Handle, '', '');//disable themes in the calendar 12 //get the vcl styles colors 13 LTextColor:=StyleServices.GetSystemColor(clWindowText); 14 LBackColor:=StyleServices.GetSystemColor(clWindow); 15 16 DateTimePicker.Color:=LBackColor; 17 //set the colors of the calendar 18 DateTimePicker.CalColors.BackColor:=LBackColor; 19 DateTimePicker.CalColors.MonthBackColor:=LBackColor; 20 DateTimePicker.CalColors.TextColor:=LTextColor; 21 DateTimePicker.CalColors.TitleBackColor:=LBackColor; 22 DateTimePicker.CalColors.TitleTextColor:=LTextColor; 23 DateTimePicker.CalColors.TrailingTextColor:=LTextColor; 24 end; 25 26 procedure TForm2.DateTimePicker1DropDown(Sender: TObject); 27 var 28 hwnd: WinAPi.Windows.HWND; 29 begin 30 hwnd := SendMessage(TDateTimePicker(Sender).Handle, DTM_GETMONTHCAL, 0,0); 31 uxTheme.SetWindowTheme(hwnd, '', '');//disable themes in the drop down window 32 end; 33 procedure TForm2.FormCreate(Sender: TObject); 34 begin 35 SetVclStylesColorsCalendar(DateTimePicker1); 36 end;