C#Datepicker backcolor,禁用手动输入

时间:2012-06-21 14:52:52

标签: c# datetimepicker

我使用下面的代码覆盖OnPaint,将backcolor属性添加到我的datatimepicker控件

   protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
        Graphics g = this.CreateGraphics();
        Rectangle dropDownRectangle = new Rectangle(ClientRectangle.Width - 17, 0, 17, 16);
        Brush bkgBrush;
        ComboBoxState visualState;
       if (this.Enabled)
        {
            bkgBrush = new SolidBrush(this.BackColor);
            visualState = ComboBoxState.Normal;
        }
        else
        {
            bkgBrush = new SolidBrush(this._backDisabledColor);
            visualState = ComboBoxState.Disabled;
        }
       g.FillRectangle(bkgBrush, 0, 0, ClientRectangle.Width, ClientRectangle.Height);
       g.DrawString(this.Text, this.Font, Brushes.Black, 0, 2);
       ComboBoxRenderer.DrawDropDownButton(g, dropDownRectangle, visualState);

        g.Dispose();
        bkgBrush.Dispose();
    }

这会禁用手动键入datetimepciker文本框。

有什么建议吗?

0 个答案:

没有答案