简体   繁体   English

有什么办法可以在C#中更改日期时间选择器的前景色

[英]Is there any way to change the fore color of the date Time picker in C#

I'm wondering if I can do it with a piece of code resembling the one below on mouse hover: 我想知道我是否可以用类似于以下鼠标悬停代码的代码来做到这一点:

    private void dobDateTimePicker_MouseHover(object sender, EventArgs e)
    {
        dobDateTimePicker.CalendarForeColor=BLUE;
    }
 dobDateTimePicker.ForeColor = Color.Green;


 dobDateTimePicker.CalendarForeColor = Color.Blue; //This line of code will do it for you.

EDIT: You may also be required to add the EnableVisualStyles() method before this can be achieved. 编辑:您可能还需要添加EnableVisualStyles()方法,然后才能实现。

You should use the System.Drawing.Color structure for this. 您应该为此使用System.Drawing.Color结构。

using System.Drawing;

dobDateTimePicker.CalendarForeColor = Color.Blue;

Note this remark's excerpt from DateTimePicker.CalendarForeColor MSDN page: 请注意此摘录摘自DateTimePicker.CalendarForeColor MSDN页面:

Starting with Windows Vista and depending on the theme, setting this property might not change the appearance of the calendar. 从Windows Vista开始,并取决于主题,设置此属性可能不会更改日历的外观。 For example, if Windows is set to use the Aero theme, setting this property has no effect. 例如,如果Windows设置为使用Aero主题,则设置此属性无效。 This is because an updated version of the calendar is rendered with an appearance that is derived at run time from the current operating system theme. 这是因为日历的更新版本呈现的外观是在运行时从当前操作系统主题派生的。 If you want to use this property and enable the earlier version of the calendar, you can disable visual styles for your application. 如果要使用此属性并启用日历的早期版本,则可以为应用程序禁用视觉样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM