2

我正在使用下面的代码覆盖 OnPaint,将背景颜色属性添加到我的 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 文本框。

有什么建议么?

4

0 回答 0