改变.NET一个DateTimePicker的背景颜色 [英] Changing the background color of a DateTimePicker in .NET

查看:1071
本文介绍了改变.NET一个DateTimePicker的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.NET (至少在2008年的版本,也许在2005年为好),改变了背景色的DateTimePicker财产绝对没有对外观的影响。如何更改不是下拉日历的文本区域的背景色,?

In .NET (at least in the 2008 version, and maybe in 2005 as well), changing the BackColor property of a DateTimePicker has absolutely no affect on the appearance. How do I change the background color of the text area, not of the drop-down calendar?

编辑:我在谈论Windows窗体,而不是ASP

I was talking about Windows forms, not ASP.

推荐答案

根据 MSDN

设置背景色有没有影响   外观的的DateTimePicker

Setting the BackColor has no effect on the appearance of the DateTimePicker.

您需要编写一个自定义的控制扩展的DateTimePicker 。重写背景色属性和的WndProc 方法。

You need to write a custom control that extends DateTimePicker. Override the BackColor property and the WndProc method.

当你修改背景色,不要忘记调用 myDTPicker.Invalidate()方法。这将迫使控制使用指定的新颜色重绘。

Whenever you change the BackColor, don't forget to call the myDTPicker.Invalidate() method. This will force the control to redrawn using the new color specified.

const int WM_ERASEBKGND = 0x14;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
     if(m.Msg == WM_ERASEBKGND)
     {
       Graphics g = Graphics.FromHdc(m.WParam);
       g.FillRectangle(new SolidBrush(_backColor), ClientRectangle);
       g.Dispose();
       return;
     }

     base.WndProc(ref m);
}

这篇关于改变.NET一个DateTimePicker的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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