* UIDatePicker: 增加可选择年、年月、年月日

This commit is contained in:
Sunny 2021-08-14 10:02:33 +08:00
parent afe718845e
commit 8b8f1bc68d
10 changed files with 92 additions and 86 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

@ -77,9 +77,6 @@ namespace Sunny.UI.Demo
System.Windows.Forms.TreeNode treeNode30 = new System.Windows.Forms.TreeNode("节点1");
System.Windows.Forms.TreeNode treeNode31 = new System.Windows.Forms.TreeNode("节点2");
System.Windows.Forms.TreeNode treeNode32 = new System.Windows.Forms.TreeNode("节点3");
this.uiComboboxEx2 = new Sunny.UI.UIComboboxEx();
this.uiComboboxEx1 = new Sunny.UI.UIComboboxEx();
this.uiLine4 = new Sunny.UI.UILine();
this.uiComboTreeView3 = new Sunny.UI.UIComboTreeView();
this.uiComboTreeView4 = new Sunny.UI.UIComboTreeView();
this.uiComboTreeView2 = new Sunny.UI.UIComboTreeView();
@ -96,57 +93,17 @@ namespace Sunny.UI.Demo
this.uiDatePicker1 = new Sunny.UI.UIDatePicker();
this.uiComboBox2 = new Sunny.UI.UIComboBox();
this.uiComboBox1 = new Sunny.UI.UIComboBox();
this.uiDatePicker2 = new Sunny.UI.UIDatePicker();
this.uiDatePicker3 = new Sunny.UI.UIDatePicker();
this.SuspendLayout();
//
// uiComboboxEx2
//
this.uiComboboxEx2.BackColor = System.Drawing.Color.White;
this.uiComboboxEx2.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.uiComboboxEx2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.uiComboboxEx2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiComboboxEx2.FormattingEnabled = true;
this.uiComboboxEx2.ItemSelectForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
this.uiComboboxEx2.Location = new System.Drawing.Point(188, 329);
this.uiComboboxEx2.Name = "uiComboboxEx2";
this.uiComboboxEx2.Size = new System.Drawing.Size(150, 30);
this.uiComboboxEx2.TabIndex = 70;
//
// uiComboboxEx1
//
this.uiComboboxEx1.BackColor = System.Drawing.Color.White;
this.uiComboboxEx1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.uiComboboxEx1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiComboboxEx1.FormattingEnabled = true;
this.uiComboboxEx1.Items.AddRange(new object[] {
"1",
"2",
"3",
"4",
"5"});
this.uiComboboxEx1.ItemSelectForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
this.uiComboboxEx1.Location = new System.Drawing.Point(30, 329);
this.uiComboboxEx1.Name = "uiComboboxEx1";
this.uiComboboxEx1.Size = new System.Drawing.Size(150, 30);
this.uiComboboxEx1.TabIndex = 69;
//
// uiLine4
//
this.uiLine4.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiLine4.Location = new System.Drawing.Point(30, 296);
this.uiLine4.MinimumSize = new System.Drawing.Size(16, 16);
this.uiLine4.Name = "uiLine4";
this.uiLine4.Size = new System.Drawing.Size(308, 20);
this.uiLine4.TabIndex = 68;
this.uiLine4.Text = "UIComboBoxEx";
this.uiLine4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// uiComboTreeView3
//
this.uiComboTreeView3.CheckBoxes = true;
this.uiComboTreeView3.DropDownStyle = Sunny.UI.UIDropDownStyle.DropDownList;
this.uiComboTreeView3.FillColor = System.Drawing.Color.White;
this.uiComboTreeView3.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiComboTreeView3.Location = new System.Drawing.Point(546, 250);
this.uiComboTreeView3.Location = new System.Drawing.Point(544, 213);
this.uiComboTreeView3.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiComboTreeView3.MinimumSize = new System.Drawing.Size(63, 0);
this.uiComboTreeView3.Name = "uiComboTreeView3";
@ -191,7 +148,7 @@ namespace Sunny.UI.Demo
this.uiComboTreeView4.DropDownStyle = Sunny.UI.UIDropDownStyle.DropDownList;
this.uiComboTreeView4.FillColor = System.Drawing.Color.White;
this.uiComboTreeView4.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiComboTreeView4.Location = new System.Drawing.Point(388, 250);
this.uiComboTreeView4.Location = new System.Drawing.Point(386, 213);
this.uiComboTreeView4.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiComboTreeView4.MinimumSize = new System.Drawing.Size(63, 0);
this.uiComboTreeView4.Name = "uiComboTreeView4";
@ -236,7 +193,7 @@ namespace Sunny.UI.Demo
this.uiComboTreeView2.DropDownStyle = Sunny.UI.UIDropDownStyle.DropDownList;
this.uiComboTreeView2.FillColor = System.Drawing.Color.White;
this.uiComboTreeView2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiComboTreeView2.Location = new System.Drawing.Point(188, 250);
this.uiComboTreeView2.Location = new System.Drawing.Point(544, 169);
this.uiComboTreeView2.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiComboTreeView2.MinimumSize = new System.Drawing.Size(63, 0);
this.uiComboTreeView2.Name = "uiComboTreeView2";
@ -262,10 +219,10 @@ namespace Sunny.UI.Demo
// uiLine1
//
this.uiLine1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiLine1.Location = new System.Drawing.Point(30, 216);
this.uiLine1.Location = new System.Drawing.Point(386, 134);
this.uiLine1.MinimumSize = new System.Drawing.Size(16, 16);
this.uiLine1.Name = "uiLine1";
this.uiLine1.Size = new System.Drawing.Size(664, 20);
this.uiLine1.Size = new System.Drawing.Size(308, 20);
this.uiLine1.TabIndex = 64;
this.uiLine1.Text = "UIComboTreeView";
this.uiLine1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@ -275,7 +232,7 @@ namespace Sunny.UI.Demo
this.uiComboTreeView1.DropDownStyle = Sunny.UI.UIDropDownStyle.DropDownList;
this.uiComboTreeView1.FillColor = System.Drawing.Color.White;
this.uiComboTreeView1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiComboTreeView1.Location = new System.Drawing.Point(30, 250);
this.uiComboTreeView1.Location = new System.Drawing.Point(386, 169);
this.uiComboTreeView1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiComboTreeView1.MinimumSize = new System.Drawing.Size(63, 0);
this.uiComboTreeView1.Name = "uiComboTreeView1";
@ -300,10 +257,10 @@ namespace Sunny.UI.Demo
// uiLine8
//
this.uiLine8.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiLine8.Location = new System.Drawing.Point(388, 137);
this.uiLine8.Location = new System.Drawing.Point(30, 257);
this.uiLine8.MinimumSize = new System.Drawing.Size(16, 16);
this.uiLine8.Name = "uiLine8";
this.uiLine8.Size = new System.Drawing.Size(306, 20);
this.uiLine8.Size = new System.Drawing.Size(308, 20);
this.uiLine8.TabIndex = 62;
this.uiLine8.Text = "UIDatetimePicker";
this.uiLine8.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@ -313,13 +270,13 @@ namespace Sunny.UI.Demo
this.uiDatetimePicker1.CanEmpty = true;
this.uiDatetimePicker1.FillColor = System.Drawing.Color.White;
this.uiDatetimePicker1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiDatetimePicker1.Location = new System.Drawing.Point(388, 171);
this.uiDatetimePicker1.Location = new System.Drawing.Point(30, 292);
this.uiDatetimePicker1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiDatetimePicker1.MaxLength = 19;
this.uiDatetimePicker1.MinimumSize = new System.Drawing.Size(63, 0);
this.uiDatetimePicker1.Name = "uiDatetimePicker1";
this.uiDatetimePicker1.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
this.uiDatetimePicker1.Size = new System.Drawing.Size(306, 29);
this.uiDatetimePicker1.Size = new System.Drawing.Size(308, 29);
this.uiDatetimePicker1.SymbolDropDown = 61555;
this.uiDatetimePicker1.SymbolNormal = 61555;
this.uiDatetimePicker1.TabIndex = 61;
@ -349,7 +306,7 @@ namespace Sunny.UI.Demo
// uiLine7
//
this.uiLine7.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiLine7.Location = new System.Drawing.Point(388, 66);
this.uiLine7.Location = new System.Drawing.Point(388, 55);
this.uiLine7.MinimumSize = new System.Drawing.Size(16, 16);
this.uiLine7.Name = "uiLine7";
this.uiLine7.Size = new System.Drawing.Size(306, 20);
@ -360,10 +317,10 @@ namespace Sunny.UI.Demo
// uiLine6
//
this.uiLine6.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiLine6.Location = new System.Drawing.Point(188, 137);
this.uiLine6.Location = new System.Drawing.Point(30, 336);
this.uiLine6.MinimumSize = new System.Drawing.Size(16, 16);
this.uiLine6.Name = "uiLine6";
this.uiLine6.Size = new System.Drawing.Size(150, 20);
this.uiLine6.Size = new System.Drawing.Size(308, 20);
this.uiLine6.TabIndex = 58;
this.uiLine6.Text = "UITimePicker";
this.uiLine6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@ -373,7 +330,7 @@ namespace Sunny.UI.Demo
this.uiTimePicker1.CanEmpty = true;
this.uiTimePicker1.FillColor = System.Drawing.Color.White;
this.uiTimePicker1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiTimePicker1.Location = new System.Drawing.Point(188, 171);
this.uiTimePicker1.Location = new System.Drawing.Point(30, 371);
this.uiTimePicker1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTimePicker1.MaxLength = 8;
this.uiTimePicker1.MinimumSize = new System.Drawing.Size(63, 0);
@ -391,10 +348,10 @@ namespace Sunny.UI.Demo
// uiLine3
//
this.uiLine3.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiLine3.Location = new System.Drawing.Point(30, 137);
this.uiLine3.Location = new System.Drawing.Point(30, 134);
this.uiLine3.MinimumSize = new System.Drawing.Size(16, 16);
this.uiLine3.Name = "uiLine3";
this.uiLine3.Size = new System.Drawing.Size(150, 20);
this.uiLine3.Size = new System.Drawing.Size(308, 20);
this.uiLine3.TabIndex = 56;
this.uiLine3.Text = "UIDatePicker";
this.uiLine3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@ -413,22 +370,22 @@ namespace Sunny.UI.Demo
// uiDatePicker1
//
this.uiDatePicker1.CanEmpty = true;
this.uiDatePicker1.DateFormat = "yyyy-MM";
this.uiDatePicker1.DateFormat = "yyyy";
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.Location = new System.Drawing.Point(30, 169);
this.uiDatePicker1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiDatePicker1.MaxLength = 7;
this.uiDatePicker1.MaxLength = 4;
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.ShowType = Sunny.UI.UIDateType.Year;
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";
this.uiDatePicker1.Text = "2020";
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);
@ -461,7 +418,7 @@ namespace Sunny.UI.Demo
"4",
"5",
"6"});
this.uiComboBox1.Location = new System.Drawing.Point(30, 89);
this.uiComboBox1.Location = new System.Drawing.Point(30, 90);
this.uiComboBox1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiComboBox1.MinimumSize = new System.Drawing.Size(63, 0);
this.uiComboBox1.Name = "uiComboBox1";
@ -472,14 +429,55 @@ namespace Sunny.UI.Demo
this.uiComboBox1.Watermark = "水印文字";
this.uiComboBox1.DropDown += new System.EventHandler(this.uiComboBox1_DropDown);
//
// uiDatePicker2
//
this.uiDatePicker2.CanEmpty = true;
this.uiDatePicker2.DateFormat = "yyyy-MM";
this.uiDatePicker2.FillColor = System.Drawing.Color.White;
this.uiDatePicker2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiDatePicker2.Location = new System.Drawing.Point(188, 169);
this.uiDatePicker2.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiDatePicker2.MaxLength = 7;
this.uiDatePicker2.MinimumSize = new System.Drawing.Size(63, 0);
this.uiDatePicker2.Name = "uiDatePicker2";
this.uiDatePicker2.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
this.uiDatePicker2.ShowToday = true;
this.uiDatePicker2.ShowType = Sunny.UI.UIDateType.YearMonth;
this.uiDatePicker2.Size = new System.Drawing.Size(150, 29);
this.uiDatePicker2.SymbolDropDown = 61555;
this.uiDatePicker2.SymbolNormal = 61555;
this.uiDatePicker2.TabIndex = 71;
this.uiDatePicker2.Text = "2020-04";
this.uiDatePicker2.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
this.uiDatePicker2.Value = new System.DateTime(2020, 4, 16, 0, 0, 0, 0);
//
// uiDatePicker3
//
this.uiDatePicker3.CanEmpty = true;
this.uiDatePicker3.FillColor = System.Drawing.Color.White;
this.uiDatePicker3.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiDatePicker3.Location = new System.Drawing.Point(30, 213);
this.uiDatePicker3.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiDatePicker3.MaxLength = 10;
this.uiDatePicker3.MinimumSize = new System.Drawing.Size(63, 0);
this.uiDatePicker3.Name = "uiDatePicker3";
this.uiDatePicker3.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
this.uiDatePicker3.ShowToday = true;
this.uiDatePicker3.Size = new System.Drawing.Size(150, 29);
this.uiDatePicker3.SymbolDropDown = 61555;
this.uiDatePicker3.SymbolNormal = 61555;
this.uiDatePicker3.TabIndex = 72;
this.uiDatePicker3.Text = "2020-04-16";
this.uiDatePicker3.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
this.uiDatePicker3.Value = new System.DateTime(2020, 4, 16, 0, 0, 0, 0);
//
// FCombobox
//
this.AllowShowTitle = true;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.uiComboboxEx2);
this.Controls.Add(this.uiComboboxEx1);
this.Controls.Add(this.uiLine4);
this.ClientSize = new System.Drawing.Size(765, 522);
this.Controls.Add(this.uiDatePicker3);
this.Controls.Add(this.uiDatePicker2);
this.Controls.Add(this.uiComboTreeView3);
this.Controls.Add(this.uiComboTreeView4);
this.Controls.Add(this.uiComboTreeView2);
@ -506,10 +504,6 @@ namespace Sunny.UI.Demo
}
#endregion
private UIComboboxEx uiComboboxEx2;
private UIComboboxEx uiComboboxEx1;
private UILine uiLine4;
private UIComboTreeView uiComboTreeView3;
private UIComboTreeView uiComboTreeView4;
private UIComboTreeView uiComboTreeView2;
@ -526,5 +520,7 @@ namespace Sunny.UI.Demo
private UIDatePicker uiDatePicker1;
private UIComboBox uiComboBox2;
private UIComboBox uiComboBox1;
private UIDatePicker uiDatePicker2;
private UIDatePicker uiDatePicker3;
}
}

View File

@ -11,9 +11,9 @@ namespace Sunny.UI.Demo
InitializeComponent();
IList<Info> infoList = new List<Info>();
Info info1 = new Info() { Id = " 1 ", Name = " 张三 " };
Info info2 = new Info() { Id = " 2 ", Name = " 李四 " };
Info info3 = new Info() { Id = " 3 ", Name = " 王五 " };
Info info1 = new Info() { Id = "1", Name = "张三" };
Info info2 = new Info() { Id = "2", Name = "李四" };
Info info3 = new Info() { Id = "3", Name = "王五" };
infoList.Add(info1);
infoList.Add(info2);
infoList.Add(info3);
@ -21,10 +21,6 @@ namespace Sunny.UI.Demo
uiComboBox2.ValueMember = "Id";
uiComboBox2.DisplayMember = "Name";
uiComboBox2.DataSource = infoList;
uiComboboxEx2.ValueMember = "Id";
uiComboboxEx2.DisplayMember = "Name";
uiComboboxEx2.DataSource = infoList;
}
public class Info

View File

@ -348,7 +348,7 @@ namespace Sunny.UI
set
{
date = value;
TabControl.SelectPage(2);
//TabControl.SelectPage(2);
Year = date.Year;
Month = date.Month;
SetYearMonth(Year, Month);
@ -367,7 +367,7 @@ namespace Sunny.UI
break;
}
TabControl_SelectedIndexChanged(TabControl, EventArgs.Empty);
}
}
@ -636,8 +636,18 @@ namespace Sunny.UI
if (iy < 0 || iy >= 12) return;
Year = years[iy] > 9999 ? 9999 : years[iy];
activeYear = -1;
TabControl.SelectedTab = tabPage2;
p2.Invalidate();
if (ShowType == UIDateType.Year)
{
date = new DateTime(Year, 1, 1);
DoValueChanged(this, Date);
CloseParent();
}
else
{
TabControl.SelectedTab = tabPage2;
p2.Invalidate();
}
}
private void p3_Paint(object sender, System.Windows.Forms.PaintEventArgs e)

View File

@ -74,6 +74,10 @@ namespace Sunny.UI
}
}
public int Year => Value.Year;
public int Month => Value.Month;
public int Day => Value.Day;
private void UIDatePicker_TextChanged(object sender, EventArgs e)
{
if (Text.Length == MaxLength)