如何更改TDateTimePicker的颜色? [英] How to change color of TDateTimePicker?

查看:51
本文介绍了如何更改TDateTimePicker的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改 TDateTimePicker 的颜色?

日期和时间选择器可以有颜色:

通常,这是通过设置颜色来完成的:

 过程TForm1.FormCreate(Sender:TObject);开始DateTimePicker1.Color:= clLime;结尾; 

但是在使用.老实说,这并不是一件充满乐趣的事情.您需要绘制整个控件.

这是您需要熟悉v6 comctl32的东西.它真的想负责控件的主题和样式.如果您想与此有所不同,那么您的自由度就会比过去少得多.

How do i change the color of a TDateTimePicker?

A Date and Time Picker can have a color:

Normally this is done by setting the Color:

procedure TForm1.FormCreate(Sender: TObject);
begin
   DateTimePicker1.Color := clLime;
end;

But when using version 6 of the Date and Time Picker Control, the color no longer works:

I tried using SetWindowTheme to disable the style of the TDateTimePicker:

procedure TForm1.FormCreate(Sender: TObject);
begin
   UxTheme.SetWindowTheme(DateTimePicker1.Handle, '', '');
   DateTimePicker1.Color := clLime;
end;

But that just made it angry:

How do i change the color of a DateTimePicker?

I was going to settle for patching the VCL:

procedure TDateTimePicker.CreateWnd;
var
  LChecked: Boolean;
begin
  LChecked := FChecked;
  inherited CreateWnd;
  SetChecked(LChecked);
  if Length(FFormat) > 0 then
     DateTime_SetFormat(Handle, FFormat);

  //20140911 Fix the .Color property not working
  if Self.HandleAllocated then
     Winapi.UxTheme.SetWindowTheme(Self.Handle, '', '');
end;

But disabling the theme of the window doesn't do it.

Bonus Chatter

You can change the color of a version 6 TComboBox with Theme Styles still applied to it:

So it's not a fundamental limitation of common controls version 6 or visual styles.

Duplicate?

i think not.

  • that question deals with how to make a DateTime picker honor the active Delphi style
  • this question deals with hot to make a DateTime picker not honor the active Delphi style

And the answers in those questions do not let you change the color; which is what i need to do.

It's even more ridiculous to suggest that those answers apply, since Style Hooks only do anything if you are using a non-standard (Delphi) style.

解决方案

How do I change the color of a TDateTimePicker?

For v6 comctl32 you cannot.

So it's not a fundamental limitation of common controls version 6 or visual styles.

Well, yes it is. Yes, v6 comctl32 allows user specified color for combo boxes. But not for date time pickers?

In order to get the result you desire you need to take over painting the control, by disabling themes for the control and handling both WM_ERASEBKGND and WM_PAINT. As Rodrigo demonstrates here: Style properties for TDateTimePicker. This is not a whole load of fun to be honest. You need to paint the entire control.

This is something you'll need to get used to with v6 comctl32. It really wants to be in charge of the theme and style of the controls. If you want to vary from that then you have much less freedom than you had in olden times.

这篇关于如何更改TDateTimePicker的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆