using ryControls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ryControls
{
    /// <summary>
    /// 增强时间控件
    /// </summary>
    public partial class DateTimePickerEX : DateTimePicker
    {
        /// <summary>
        /// 增强时间控件
        /// </summary>
        public DateTimePickerEX()
        {
            InitializeComponent();
            this.Format = DateTimePickerFormat.Custom;
            this.CustomFormat = "yyyy年MM月dd日 dddd";
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="m"></param>
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            //WM_PAINT = 0xf; 要求一个窗口重画自己,即Paint事件时  
            //WM_CTLCOLOREDIT = 0x133;当一个编辑型控件将要被绘制时发送此消息给它的父窗口；  
            //通过响应这条消息，所有者窗口可以通过使用给定的相关显示设备的句柄来设置编辑框的文本和背景颜色  
            //windows消息值表,可参考:http://hi.baidu.com/dooy/blog/item/0e770a24f70e3b2cd407421b.html  
            if (m.Msg == 0xf || m.Msg == 0x133)
            {
                IntPtr hDC =Win32.GetWindowDC(m.HWnd);
                if (hDC.ToInt32() == 0) //如果取设备上下文失败则返回  
                {
                    return;
                }

                //建立Graphics对像  
                Graphics g = Graphics.FromHdc(hDC);
                //画边框的   
                ControlPaint.DrawBorder(g, new Rectangle(0, 0, Width, Height), SkinHelp.DefalutBorderColor, ButtonBorderStyle.Solid);
                //画坚线  
                //ControlPaint.DrawBorder(g, new Rectangle(Width - Height, 0, Height, Height), Color.Red, ButtonBorderStyle.Solid);
                //g.DrawLine(new Pen(Brushes.Blue, 2), new PointF(this.Width - this.Height, 0), new PointF(this.Width - this.Height, this.Height));  
                //释放DC    
                Win32.ReleaseDC(m.HWnd, hDC);
            }
        }
    }
}
