- if (clip_rectangle.IntersectsWith (dtp.date_area_rect)) {
- // fill the background
- dc.FillRectangle (SystemBrushes.Window, dtp.date_area_rect);
-
- // fill the currently highlighted area
- if (dtp.hilight_date_area != Rectangle.Empty) {
- dc.FillRectangle (SystemBrushes.Highlight, dtp.hilight_date_area);
+ if (!clip_rectangle.IntersectsWith (dtp.date_area_rect))
+ return;
+
+ // fill the background
+ dc.FillRectangle (SystemBrushes.Window, dtp.date_area_rect);
+
+ // Update date_area_rect if we are drawing the checkbox
+ Rectangle date_area_rect = dtp.date_area_rect;
+ if (dtp.ShowCheckBox) {
+ Rectangle check_box_rect = dtp.CheckBoxRect;
+ date_area_rect.X = date_area_rect.X + check_box_rect.Width + DateTimePicker.check_box_space * 2;
+ date_area_rect.Width = date_area_rect.Width - check_box_rect.Width - DateTimePicker.check_box_space * 2;
+
+ ButtonState bs = dtp.Checked ? ButtonState.Checked : ButtonState.Normal;
+ CPDrawCheckBox(dc, check_box_rect, bs);
+
+ if (dtp.is_checkbox_selected)
+ CPDrawFocusRectangle (dc, check_box_rect, dtp.foreground_color, dtp.background_color);
+ }
+
+ // render each text part
+ using (StringFormat text_format = StringFormat.GenericTypographic)
+ {
+ text_format.LineAlignment = StringAlignment.Near;
+ text_format.Alignment = StringAlignment.Near;
+ text_format.FormatFlags = text_format.FormatFlags | StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox;
+ text_format.FormatFlags &= ~StringFormatFlags.NoClip;
+
+ // Calculate the rectangles for each part
+ if (dtp.part_data.Length > 0 && dtp.part_data[0].drawing_rectangle.IsEmpty)
+ {
+ Graphics gr = dc;
+ for (int i = 0; i < dtp.part_data.Length; i++)
+ {
+ DateTimePicker.PartData fd = dtp.part_data[i];
+ RectangleF text_rect = new RectangleF();
+ string text = fd.GetText(dtp.Value);
+ text_rect.Size = gr.MeasureString (text, dtp.Font, 250, text_format);
+ if (!fd.is_literal)
+ text_rect.Width = Math.Max (dtp.CalculateMaxWidth(fd.value, gr, text_format), text_rect.Width);
+
+ if (i > 0) {
+ text_rect.X = dtp.part_data[i - 1].drawing_rectangle.Right;
+ } else {
+ text_rect.X = date_area_rect.X;
+ }
+ text_rect.Y = 2;
+ text_rect.Inflate (1, 0);
+ fd.drawing_rectangle = text_rect;
+ }