Date Date Select beautify controls ---------- WinForm Control Development Series

Here is the source code control to display the interface, date selection panel too much about 3000 lines of source code, not posted, you can download the source code to see. You can improve this date controls.

 ///  <Summary> 
  /// date selection control landscaping
   ///  </ Summary> 
  [the ToolboxItem ( to true )] 
  [, DefaultProperty ( " the DatePicker " )] 
  [the Description ( " date selection control beautification " )]
   public  partial  class DateExt: Control 
  { 
    #region 

    Private  BOOL backBorderShow = to true ;
     ///  <Summary> 
    /// whether to show border
     ///  </ Summary> 
    [the DefaultValue ( to true )] 
    [the Description ( " whether to show border")]
    public bool BackBorderShow
    {
      get { return this.backBorderShow; }
      set
      {
        if (this.backBorderShow == value)
          return;
        this.backBorderShow = value;
        this.Invalidate();
      }
    }

    private ImageAnchors imageAnchor = ImageAnchors.Right;
    /// <summary>
    /// 图片位置
    /// </summary>
    [DefaultValue(ImageAnchors.Right)]
    [Description("图片位置")]
    public ImageAnchors ImageAnchor
    {
      get { return this.imageAnchor; }
      set
      {
        if (this.imageAnchor == value)
          return;
        this.imageAnchor = value;
        this.Invalidate();
      }
    }

    private Color backBorderColor = Color.FromArgb(192, 192, 192);
    /// <summary>
    /// 边框颜色
    /// </summary>
    [DefaultValue(typeof(Color), "192, 192, 192")]
    [Description("边框颜色")]
    [Editor(typeof(ColorEditorExt), typeof(System.Drawing.Design.UITypeEditor))]
    public Color BackBorderColor
    {
      get { return this.backBorderColor; }
      set
      {
        if (this.backBorderColor == value)
          return;
        this.backBorderColor = value;
        this.Invalidate();
      }
    }

    private DatePickerExt datePicker = null;
    /// <summary>
    /// 日期选择面板
    /// </summary>
    [Browsable(true)]
    [Description("日期选择面板")]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    public DatePickerExt DatePicker
    {
      get { return this.datePicker; }
      set { this.datePicker = value; }
    }

    protected override Size DefaultSize
    {
      get
      {
        return new Size(130, 23);
      }
    }

    protected override Cursor DefaultCursor
    {
      get
      {
        return Cursors.Hand;
      }
    }

    /// <summary>
    /// 日期面板显示状态
    /// </summary>
    private bool DisplayStatus = false;

    private ToolStripDropDown tsdd = null;

    private ToolStripControlHost tsch = null;

    private readonly StringFormat date_sf = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, Trimming = StringTrimming.None, FormatFlags = StringFormatFlags.NoWrap };

    #endregion

    public DateExt()
    {
      SetStyle(ControlStyles.UserPaint, true);
      SetStyle(ControlStyles.AllPaintingInWmPaint, true);
      SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
      SetStyle(ControlStyles.ResizeRedraw, true);
      SetStyle(ControlStyles.SupportsTransparentBackColor, true);
      InitializeComponent();

      this.BackColor = Color.FromArgb(255, 255, 255);
      this.ForeColor = Color.FromArgb(105, 105, 105);
      this.Font = new Font("微软雅黑", 9);

      this.DatePicker = new DatePickerExt();
      this.tsdd = new ToolStripDropDown() { Padding = Padding.Empty };
      this.tsch = new ToolStripControlHost(this.DatePicker) { Margin = Padding.Empty, Padding = Padding.Empty };
      tsdd.Items.Add(this.tsch);


      this.tsdd.Closed += new ToolStripDropDownClosedEventHandler(this.tsdd_Closed);
      this.DatePicker.BottomBarConfirmClick += new DatePickerExt.BottomBarIiemClickEvent(this.DatePicker_BottomBarConfirmClick);

    }

    protected override void OnPaint(PaintEventArgs e)
    {
      base.OnPaint(e);
      Graphics g = e.Graphics;

      if (this.BackBorderShow)
      {
        Pen backborder_pen = new Pen(this.BackBorderColor, 1);
        g.DrawRectangle(backborder_pen, new Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 1));
        backborder_pen.Dispose();
      }

      string date_format = this.DatePicker.DateDisplayType == DatePickerExt.DateDisplayTypes.Year ? "yyyy" : (this.DatePicker.DateDisplayType == DatePickerExt.DateDisplayTypes.YearMonth ? "yyyy-MM" : "yyyy-MM-dd");
      int image_width = global::AnimationLibrary.Properties.Resources.date.Width;
      int image_height = global::AnimationLibrary.Properties.Resources.date.Height;
      Rectangle image_rect = new Rectangle(e.ClipRectangle.Right - image_width - 2, (e.ClipRectangle.Y + e.ClipRectangle.Height - image_height) / 2, 16, 16);
      Rectangle date_rect = new Rectangle(e.ClipRectangle.X + 5, e.ClipRectangle.Y, e.ClipRectangle.Width - image_width - 12, e.ClipRectangle.Height);
      if (this.ImageAnchor == ImageAnchors.Left)
      {
        image_rect = new Rectangle(e.ClipRectangle.X + 2, (e.ClipRectangle.Y + e.ClipRectangle.Height - image_height) / 2, 16, 16);
        date_rect = new Rectangle(e.ClipRectangle.X + 2 + image_width + 5, e.ClipRectangle.Y, e.ClipRectangle.Width - image_width - 12, e.ClipRectangle.Height);
      }
      SolidBrush date_sb = new SolidBrush(this.ForeColor);
      g.DrawImage(global::AnimationLibrary.Properties.Resources.date, image_rect);
      g.DrawString(this.DatePicker.Value.ToString(date_format), this.Font, date_sb, date_rect, date_sf);
      date_sb.Dispose();
    }

    protected override void OnClick(EventArgs e)
    {
      base.OnClick(e);
      if (!this.DisplayStatus)
      {
        tsdd.Show(this.PointToScreen(new Point(0, this.Height + 2)));
      }
    }

    protected override void Dispose(bool disposing)
    {
      if (disposing && (components != null))
      {
        components.Dispose();
        if (this.date_sf != null)
          this.date_sf.Dispose();
      }
      base.Dispose(disposing);
    }

    private void DatePicker_BottomBarConfirmClick(object sender, DatePickerExt.BottomBarIiemEventArgs e)
    {
      this.tsdd.Close();
      this.DisplayStatus = false;
      this.Invalidate();
    }

    private void tsdd_Closed(object sender, ToolStripDropDownClosedEventArgs e)
    {
      this.Invalidate();
      this.DisplayStatus = false;
    }

    /// <summary>
    /// 图片位置
    /// </summary>
    [Description("图片位置")]
    public enum ImageAnchors
    {
      /// <summary>
      /// left
       ///  </ Summary> 
      Left,
       ///  <Summary> 
      /// the right
       ///  </ Summary> 
      Right 
    } 

  }

Source Downloads: date selection controls beautification .zip

Guess you like

Origin www.cnblogs.com/tlmbem/p/11480577.html