Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7857801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:09:23+00:00 2026-06-02T21:09:23+00:00

A TDateTime picker is a ComboBox where the drop-down list is replaced with a

  • 0

A TDateTime picker is a ComboBox where the drop-down list is replaced with a calendar.
I use XE2 VCL Styles and changing style does’nt affect TDateTimePicker Color & Font Color.
I have change the Calendar style with this question but the solution is not OK for the ComboBox, any idea ?
Now I plan to inherit a TComboBox for use with a TMonthCalendar but I would know if anybody had a better solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:09:25+00:00Added an answer on June 2, 2026 at 9:09 pm

    In order to use the workaround of the CalColors property, you must disable the Windows Theme in the drop down window of the TDateTimePicker component, for that you must use the
    DTM_GETMONTHCAL message to get the window handle.

    Check this sample App

    unit Unit15;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ImgList, Vcl.StdCtrls, Vcl.ComCtrls;
    
    type
      TForm15 = class(TForm)
        DateTimePicker1: TDateTimePicker;
        procedure DateTimePicker1DropDown(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form15: TForm15;
    
    implementation
    
    
    {$R *.dfm}
    
    uses
      Winapi.CommCtrl,
      Vcl.Styles,
      Vcl.Themes,
      uxTheme;
    
    Procedure SetVclStylesColorsCalendar( DateTimePicker: TDateTimePicker);
    Var
      LTextColor, LBackColor : TColor;
    begin
       uxTheme.SetWindowTheme(DateTimePicker.Handle, '', '');//disable themes in the calendar
       //get the vcl styles colors
       LTextColor:=StyleServices.GetSystemColor(clWindowText);
       LBackColor:=StyleServices.GetSystemColor(clWindow);
    
       DateTimePicker.Color:=LBackColor;
       //set the colors of the calendar
       DateTimePicker.CalColors.BackColor:=LBackColor;
       DateTimePicker.CalColors.MonthBackColor:=LBackColor;
       DateTimePicker.CalColors.TextColor:=LTextColor;
       DateTimePicker.CalColors.TitleBackColor:=LBackColor;
       DateTimePicker.CalColors.TitleTextColor:=LTextColor;
       DateTimePicker.CalColors.TrailingTextColor:=LTextColor;
    end;
    
    
    procedure TForm15.DateTimePicker1DropDown(Sender: TObject);
    var
      hwnd: WinAPi.Windows.HWND;
    begin
      hwnd := SendMessage(TDateTimePicker(Sender).Handle, DTM_GETMONTHCAL, 0,0);
      uxTheme.SetWindowTheme(hwnd, '', '');//disable themes in the drop down window
    end;
    
    procedure TForm15.FormCreate(Sender: TObject);
    begin
      SetVclStylesColorsCalendar( DateTimePicker1);
    end;
    
    end.
    

    enter image description here

    UPDATE 1

    Change the background color of the “combobox” of the TDateTimePicker is a task limited by windows itself, because between others factors

    1. This control doesn’t have the owner drawn capacity,
    2. And if you try using the SetBkColor function has not effect in this control because the WM_CTLCOLOREDIT message is not handled by this control.

    So a possible solution is intercept the WM_PAINT and WM_ERASEBKGND messages and wrote your own code to paint the control. When you uses the Vcl Styles you can use a Style hook to handle these messages.

    Check this code (only as a proof of concept)

    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ImgList, Vcl.StdCtrls, Vcl.ComCtrls;
    
    type
      TForm15 = class(TForm)
        DateTimePicker1: TDateTimePicker;
        DateTimePicker2: TDateTimePicker;
        procedure DateTimePicker1DropDown(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      end;
    
    
    var
      Form15: TForm15;
    
    implementation
    
    
    {$R *.dfm}
    
    uses
      Winapi.CommCtrl,
      Vcl.Styles,
      Vcl.Themes,
      Winapi.uxTheme;
    
    type
     TDateTimePickerStyleHookFix= class(TDateTimePickerStyleHook)
     private
        procedure WMPaint(var Message: TMessage); message WM_PAINT;
        procedure PaintBackground(Canvas: TCanvas); override;
     public
        constructor Create(AControl: TWinControl); override;
     end;
    
     TDateTimePickerStyleHookHelper = class helper for TDateTimePickerStyleHook
     public
        function GetButtonRect_: TRect;
     end;
    
    
    Procedure SetVclStylesColorsCalendar( DateTimePicker: TDateTimePicker);
    Var
      LTextColor, LBackColor : TColor;
    begin
       Winapi.uxTheme.SetWindowTheme(DateTimePicker.Handle, '', '');//disable themes in the calendar
       //get the vcl styles colors
       LTextColor:=StyleServices.GetSystemColor(clWindowText);
       LBackColor:=StyleServices.GetSystemColor(clWindow);
    
       DateTimePicker.Color:=LBackColor;
       //set the colors of the calendar
       DateTimePicker.CalColors.BackColor:=LBackColor;
       DateTimePicker.CalColors.MonthBackColor:=LBackColor;
       DateTimePicker.CalColors.TextColor:=LTextColor;
       DateTimePicker.CalColors.TitleBackColor:=LBackColor;
       DateTimePicker.CalColors.TitleTextColor:=LTextColor;
       DateTimePicker.CalColors.TrailingTextColor:=LTextColor;
    end;
    
    
    procedure TForm15.DateTimePicker1DropDown(Sender: TObject);
    var
      hwnd: WinAPi.Windows.HWND;
    begin
      hwnd := SendMessage(TDateTimePicker(Sender).Handle, DTM_GETMONTHCAL, 0,0);
      Winapi.uxTheme.SetWindowTheme(hwnd, '', '');//disable themes in the drop down window
    end;
    
    procedure TForm15.FormCreate(Sender: TObject);
    begin
      //set the colors for the TDateTimePicker
      SetVclStylesColorsCalendar( DateTimePicker1);
      SetVclStylesColorsCalendar( DateTimePicker2);
    end;
    
    
    { TDateTimePickerStyleHookHelper }
    function TDateTimePickerStyleHookHelper.GetButtonRect_: TRect;
    begin
     Result:=Self.GetButtonRect;
    end;
    
    { TDateTimePickerStyleHookFix }
    constructor TDateTimePickerStyleHookFix.Create(AControl: TWinControl);
    begin
      inherited;
      OverrideEraseBkgnd:=True;//this indicates which this style hook will call the PaintBackground method when the WM_ERASEBKGND message is sent.
    end;
    
    procedure TDateTimePickerStyleHookFix.PaintBackground(Canvas: TCanvas);
    begin
      //use the proper style color to paint the background
      Canvas.Brush.Color := StyleServices.GetStyleColor(scEdit);
      Canvas.FillRect(Control.ClientRect);
    end;
    
    procedure TDateTimePickerStyleHookFix.WMPaint(var Message: TMessage);
    var
      DC: HDC;
      LCanvas: TCanvas;
      LPaintStruct: TPaintStruct;
      LRect: TRect;
      LDetails: TThemedElementDetails;
      sDateTime  : string;
    begin
      DC := Message.WParam;
      LCanvas := TCanvas.Create;
      try
        if DC <> 0 then
          LCanvas.Handle := DC
        else
          LCanvas.Handle := BeginPaint(Control.Handle, LPaintStruct);
        if TStyleManager.SystemStyle.Enabled then
        begin
          PaintNC(LCanvas);
          Paint(LCanvas);
        end;
        if DateMode = dmUpDown then
          LRect := Rect(2, 2, Control.Width - 2, Control.Height - 2)
        else
          LRect := Rect(2, 2, GetButtonRect_.Left, Control.Height - 2);
        if ShowCheckBox then LRect.Left := LRect.Height + 2;
        IntersectClipRect(LCanvas.Handle, LRect.Left, LRect.Top, LRect.Right, LRect.Bottom);
        Message.wParam := WPARAM(LCanvas.Handle);
    
        //only works for DateFormat = dfShort
        case TDateTimePicker(Control).Kind of
         dtkDate : sDateTime:=DateToStr(TDateTimePicker(Control).DateTime);
         dtkTime : sDateTime:=TimeToStr(TDateTimePicker(Control).DateTime);
        end;
    
        //draw the current date/time value
        LDetails := StyleServices.GetElementDetails(teEditTextNormal);
        DrawControlText(LCanvas, LDetails, sDateTime, LRect, DT_VCENTER or DT_LEFT);
    
        if not TStyleManager.SystemStyle.Enabled then
          Paint(LCanvas);
        Message.WParam := DC;
        if DC = 0 then
          EndPaint(Control.Handle, LPaintStruct);
      finally
        LCanvas.Handle := 0;
        LCanvas.Free;
      end;
      Handled := True;
    end;
    
    
    initialization
      TStyleManager.Engine.RegisterStyleHook(TDateTimePicker, TDateTimePickerStyleHookFix);
    
    end.
    

    Note: This style hook doesn’t draw the focused (selected) elements in the Inner text control (combobox) of the TDateTimePicker, i let this task for you.

    enter image description here

    UPDATE 2

    I just wrote a vcl style hook which includes all the logic to apply the vcl style properly to the TDateTimePicker component, without use the OnDropDown event or the OnCreate event of the form. You can find the vcl style hook here (as part of the vcl styles utils project)

    To use it you must add the Vcl.Styles.DateTimePickers unit to your project and register the hook in this way.

      TStyleManager.Engine.RegisterStyleHook(TDateTimePicker, TDateTimePickerStyleHookFix);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to use a date picker, but i am not sure how
I have a problem with search form. I use date-time picker for user to
I want to use datetime picker in 4 text box. JQuery datepicker for 4
As the properties Value of the date/time picker does not allow to enter the
I am trying to use the DateTime picker custom gridview column type from this
I use jquery.pttimeselect.js to create datetime picker. How to change its background? The css
I have one issue with Datetime Picker In my firstview i have button.If i
I have a TDateTime variable which is assigned a value at runtime of 40510.416667.
I have a TDateTime value (that I get as result from EndOfTheMonth(date) ) to
datetime.datetime.utcnow() Why does this datetime not have any timezone info given that it is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.