title: Changing the border color of a DateTimePicker with ShowCheckBox property set
body: <p>Changing the border color using the property of a DateTimePicker has absolutely no effect on the appearance. How do I change the border color to red for error validation if the field is empty of the datetimepicker (<code>showCheckbox</code> property <strong>true</strong> and the checkbox is unchecked).</p>
  <p>Edit1: I was talking about Windows Forms. I also tried the code below, but no luck.<br />
  Edit2:  for example, DateTimePicker control <code>TextChanged</code> event or <code>ShowCheckbox</code> is an unchecked event if the text is empty, it will change the border color to red.</p>
  <p>Edit3: <a href="https://ibb.co/T04W8M0" rel="nofollow noreferrer">https://ibb.co/T04W8M0</a> If the checkbox is unchecked and text area showing empty then border-color should be red in color.</p>
  <p><a href="https://www.codeproject.com/Articles/30660/A-DateTimePicker-with-working-BackColor" rel="nofollow noreferrer">https://www.codeproject.com/Articles/30660/A-DateTimePicker-with-working-BackColor</a> (<code>ShowCheckbox</code> is true, not set here)</p>
  <p><a href="https://stackoverflow.com/questions/198532/changing-the-background-color-of-a-datetimepicker-in-net/#answer-46486746">Changing the background color of a DateTimePicker in .NET</a> (<code>ShowCheckbox</code> is true, not set here)</p>
  <pre><code>protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  {
      Graphics g = this.CreateGraphics();
  
      //The dropDownRectangle defines position and size of dropdownbutton block, 
      //the width is fixed to 17 and height to 16. 
      //The dropdownbutton is aligned to right
      Rectangle dropDownRectangle = 
         new Rectangle(ClientRectangle.Width - 17, 0, 17, 16);
      Brush bkgBrush;
      ComboBoxState visualState;
  
      //When the control is enabled the brush is set to Backcolor, 
      //otherwise to color stored in _backDisabledColor
      if (this.Enabled) {
           bkgBrush = new SolidBrush(this.BackColor);
           visualState = ComboBoxState.Normal;
      }
      else {
          bkgBrush = new SolidBrush(this._backDisabledColor);
          visualState = ComboBoxState.Disabled;
      }
  
      // Painting...in action
  
      //Filling the background
      g.FillRectangle(bkgBrush, 0, 0, ClientRectangle.Width, ClientRectangle.Height);
      
      //Drawing the datetime text
      g.DrawString(this.Text, this.Font, Brushes.Black, 0, 2);
  
      //Drawing the dropdownbutton using ComboBoxRenderer
      ComboBoxRenderer.DrawDropDownButton(g, dropDownRectangle, visualState);
  
      g.Dispose();
      bkgBrush.Dispose();
  }
  </code></pre>