* UIDatePicker: 增加月份选择

This commit is contained in:
Sunny 2021-08-13 23:49:03 +08:00
parent d4cf6f4d01
commit afe718845e
10 changed files with 71 additions and 5 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -413,20 +413,22 @@ namespace Sunny.UI.Demo
// uiDatePicker1
//
this.uiDatePicker1.CanEmpty = true;
this.uiDatePicker1.DateFormat = "yyyy-MM";
this.uiDatePicker1.FillColor = System.Drawing.Color.White;
this.uiDatePicker1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiDatePicker1.Location = new System.Drawing.Point(30, 171);
this.uiDatePicker1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiDatePicker1.MaxLength = 10;
this.uiDatePicker1.MaxLength = 7;
this.uiDatePicker1.MinimumSize = new System.Drawing.Size(63, 0);
this.uiDatePicker1.Name = "uiDatePicker1";
this.uiDatePicker1.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
this.uiDatePicker1.ShowToday = true;
this.uiDatePicker1.ShowType = Sunny.UI.UIDateType.YearMonth;
this.uiDatePicker1.Size = new System.Drawing.Size(150, 29);
this.uiDatePicker1.SymbolDropDown = 61555;
this.uiDatePicker1.SymbolNormal = 61555;
this.uiDatePicker1.TabIndex = 54;
this.uiDatePicker1.Text = "2020-04-16";
this.uiDatePicker1.Text = "2020-04";
this.uiDatePicker1.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
this.uiDatePicker1.Value = new System.DateTime(2020, 4, 16, 0, 0, 0, 0);
this.uiDatePicker1.ValueChanged += new Sunny.UI.UIDatePicker.OnDateTimeChanged(this.uiDatePicker1_ValueChanged);

View File

@ -23,6 +23,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
namespace Sunny.UI
@ -352,10 +353,28 @@ namespace Sunny.UI
Month = date.Month;
SetYearMonth(Year, Month);
activeDay = -1;
TabControl.SelectedTab = tabPage3;
switch (ShowType)
{
case UIDateType.YearMonthDay:
TabControl.SelectedTab = tabPage3;
break;
case UIDateType.YearMonth:
TabControl.SelectedTab = tabPage2;
break;
case UIDateType.Year:
TabControl.SelectedTab = tabPage1;
break;
}
}
}
[DefaultValue(UIDateType.YearMonthDay)]
[Description("日期显示类型"), Category("SunnyUI")]
public UIDateType ShowType { get; set; }
private int year;
public int Year
@ -542,7 +561,17 @@ namespace Sunny.UI
if (Month <= 0 || Month > 12) return;
SetYearMonth(Year, Month);
activeMonth = -1;
TabControl.SelectedTab = tabPage3;
if (ShowType == UIDateType.YearMonth)
{
date = new DateTime(Year, Month, 1);
DoValueChanged(this, Date);
CloseParent();
}
else
{
TabControl.SelectedTab = tabPage3;
}
}
private int activeMonth = -1;
@ -659,7 +688,7 @@ namespace Sunny.UI
using (Font SubFont = new Font("微软雅黑", 10.5f))
{
e.Graphics.FillRectangle(p3.FillColor, p3.Width - width * 4 + 1, p3.Height - height + 1, width * 4 - 2, height - 2);
e.Graphics.FillRoundRectangle(PrimaryColor, new Rectangle((int)(p3.Width - width * 4 + 6), p3.Height - height + 3, 8, height - 10), 3);
e.Graphics.FillRoundRectangle(PrimaryColor, new Rectangle(p3.Width - width * 4 + 6, p3.Height - height + 3, 8, height - 10), 3);
sf = e.Graphics.MeasureString(UILocalize.Today + ": " + DateTime.Now.DateString(), SubFont);
e.Graphics.DrawString(UILocalize.Today + ": " + DateTime.Now.DateString(), SubFont, isToday ? PrimaryColor : Color.DarkGray, p3.Width - width * 4 + 17, p3.Height - height - 1 + (height - sf.Height) / 2.0f);

View File

@ -49,6 +49,31 @@ namespace Sunny.UI
[Description("日期输入时,显示今日按钮"), Category("SunnyUI")]
public bool ShowToday { get; set; }
private UIDateType showType = UIDateType.YearMonthDay;
[DefaultValue(UIDateType.YearMonthDay)]
[Description("日期显示类型"), Category("SunnyUI")]
public UIDateType ShowType
{
get => showType;
set
{
showType = value;
switch (value)
{
case UIDateType.YearMonthDay:
DateFormat = "yyyy-MM-dd";
break;
case UIDateType.YearMonth:
DateFormat = "yyyy-MM";
break;
case UIDateType.Year:
DateFormat = "yyyy";
break;
}
}
}
private void UIDatePicker_TextChanged(object sender, EventArgs e)
{
if (Text.Length == MaxLength)
@ -115,6 +140,7 @@ namespace Sunny.UI
private void UIDatetimePicker_ButtonClick(object sender, EventArgs e)
{
item.ShowType = ShowType;
item.Date = Value;
item.ShowToday = ShowToday;
item.PrimaryColor = RectColor;

9
SunnyUI/Units/UDefine.cs Normal file
View File

@ -0,0 +1,9 @@
namespace Sunny.UI
{
public enum UIDateType
{
YearMonthDay,
YearMonth,
Year
}
}