2

以下のコードを使用して 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 テキストボックスへの手動入力が無効になります。

助言がありますか?

4

0 に答える 0