c# Winform 只有年份和月份 的时间控件 10
谢谢啊 ,解决的 +50分 展开
没有现成的,用自定义控件,界面按照下面布置就可以了,没时间作,只画了一下界面,
ExtControls.ExtButton();
是自己继承按钮控件扩展的,你用普通按钮替换下,看看效果,点击下拉按钮让plBottom可见,
注意处理下微妙控制,
月份的修改参照DateTimePicker,为lblRight添加右键菜单就可以了
partial class YearMonthPacker: UserControl
{
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 使用中のリソースをすべてクリーンアップします。
/// </summary>
public YearMonthPacker()
{
InitializeComponent();
}
/// <param name="disposing">マネージ リソースが破弃される场合 true、破弃されない场合は false です。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region コンポーネント デザイナで生成されたコード
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent()
{
this.plTop = new System.Windows.Forms.Panel();
this.btnDropDown = new ExtControls.ExtButton();
this.plBottom = new System.Windows.Forms.Panel();
this.lblMonth = new System.Windows.Forms.Label();
this.txtMonth = new System.Windows.Forms.TextBox();
this.lblYear = new System.Windows.Forms.Label();
this.txtYear = new System.Windows.Forms.TextBox();
this.panel1 = new System.Windows.Forms.Panel();
this.btnLeft = new ExtControls.ExtButton();
this.panel2 = new System.Windows.Forms.Panel();
this.btnRight = new ExtControls.ExtButton();
this.plMiddle = new System.Windows.Forms.Panel();
this.label1 = new System.Windows.Forms.Label();
this.lblBYear = new System.Windows.Forms.Label();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.plTop.SuspendLayout();
this.plBottom.SuspendLayout();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.plMiddle.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.SuspendLayout();
//
// plTop
//
this.plTop.BackColor = System.Drawing.SystemColors.Window;
this.plTop.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.plTop.Controls.Add(this.txtYear);
this.plTop.Controls.Add(this.lblYear);
this.plTop.Controls.Add(this.txtMonth);
this.plTop.Controls.Add(this.lblMonth);
this.plTop.Controls.Add(this.btnDropDown);
this.plTop.Dock = System.Windows.Forms.DockStyle.Top;
this.plTop.Location = new System.Drawing.Point(0, 0);
this.plTop.Name = "plTop";
this.plTop.Size = new System.Drawing.Size(190, 22);
this.plTop.TabIndex = 0;
//
// btnDropDown
//
this.btnDropDown.ButtonType = ExtControls.ArrowButtonType.DownArrow;
this.btnDropDown.Dock = System.Windows.Forms.DockStyle.Right;
this.btnDropDown.Location = new System.Drawing.Point(164, 0);
this.btnDropDown.Name = "btnDropDown";
this.btnDropDown.Padding = new System.Windows.Forms.Padding(3);
this.btnDropDown.Size = new System.Drawing.Size(22, 18);
this.btnDropDown.TabIndex = 0;
this.btnDropDown.UseVisualStyleBackColor = true;
//
// plBottom
//
this.plBottom.Controls.Add(this.plMiddle);
this.plBottom.Controls.Add(this.panel2);
this.plBottom.Controls.Add(this.panel1);
this.plBottom.Dock = System.Windows.Forms.DockStyle.Fill;
this.plBottom.Location = new System.Drawing.Point(0, 22);
this.plBottom.Name = "plBottom";
this.plBottom.Size = new System.Drawing.Size(190, 37);
this.plBottom.TabIndex = 1;
//
// lblMonth
//
this.lblMonth.Dock = System.Windows.Forms.DockStyle.Right;
this.lblMonth.Location = new System.Drawing.Point(136, 0);
this.lblMonth.Name = "lblMonth";
this.lblMonth.Size = new System.Drawing.Size(28, 18);
this.lblMonth.TabIndex = 5;
this.lblMonth.Text = "月";
this.lblMonth.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// txtMonth
//
this.txtMonth.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txtMonth.Dock = System.Windows.Forms.DockStyle.Right;
this.txtMonth.Location = new System.Drawing.Point(102, 0);
this.txtMonth.Margin = new System.Windows.Forms.Padding(0);
this.txtMonth.MaxLength = 2;
this.txtMonth.Multiline = true;
this.txtMonth.Name = "txtMonth";
this.txtMonth.Size = new System.Drawing.Size(34, 18);
this.txtMonth.TabIndex = 2;
this.txtMonth.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// lblYear
//
this.lblYear.Dock = System.Windows.Forms.DockStyle.Right;
this.lblYear.Location = new System.Drawing.Point(74, 0);
this.lblYear.Name = "lblYear";
this.lblYear.Size = new System.Drawing.Size(28, 18);
this.lblYear.TabIndex = 7;
this.lblYear.Text = "年";
this.lblYear.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// txtYear
//
this.txtYear.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txtYear.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtYear.Location = new System.Drawing.Point(0, 0);
this.txtYear.Margin = new System.Windows.Forms.Padding(0);
this.txtYear.MaxLength = 4;
this.txtYear.Multiline = true;
this.txtYear.Name = "txtYear";
this.txtYear.Size = new System.Drawing.Size(74, 18);
this.txtYear.TabIndex = 1;
this.txtYear.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// panel1
//
this.panel1.Controls.Add(this.btnLeft);
this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Padding = new System.Windows.Forms.Padding(5, 10, 0, 10);
this.panel1.Size = new System.Drawing.Size(34, 37);
this.panel1.TabIndex = 1;
//
// btnLeft
//
this.btnLeft.ButtonType = ExtControls.ArrowButtonType.LeftArrow;
this.btnLeft.Dock = System.Windows.Forms.DockStyle.Fill;
this.btnLeft.Location = new System.Drawing.Point(5, 10);
this.btnLeft.Name = "btnLeft";
this.btnLeft.Size = new System.Drawing.Size(29, 17);
this.btnLeft.TabIndex = 1;
this.btnLeft.UseVisualStyleBackColor = true;
//
// panel2
//
this.panel2.Controls.Add(this.btnRight);
this.panel2.Dock = System.Windows.Forms.DockStyle.Right;
this.panel2.Location = new System.Drawing.Point(156, 0);
this.panel2.Name = "panel2";
this.panel2.Padding = new System.Windows.Forms.Padding(0, 10, 5, 10);
this.panel2.Size = new System.Drawing.Size(34, 37);
this.panel2.TabIndex = 2;
//
// btnRight
//
this.btnRight.ButtonType = ExtControls.ArrowButtonType.RightArrow;
this.btnRight.Dock = System.Windows.Forms.DockStyle.Fill;
this.btnRight.Location = new System.Drawing.Point(0, 10);
this.btnRight.Name = "btnRight";
this.btnRight.Size = new System.Drawing.Size(29, 17);
this.btnRight.TabIndex = 1;
this.btnRight.UseVisualStyleBackColor = true;
//
// plMiddle
//
this.plMiddle.Controls.Add(this.numericUpDown1);
this.plMiddle.Controls.Add(this.lblBYear);
this.plMiddle.Controls.Add(this.label1);
this.plMiddle.Dock = System.Windows.Forms.DockStyle.Fill;
this.plMiddle.Location = new System.Drawing.Point(34, 0);
this.plMiddle.Name = "plMiddle";
this.plMiddle.Padding = new System.Windows.Forms.Padding(0, 4, 0, 4);
this.plMiddle.Size = new System.Drawing.Size(122, 37);
this.plMiddle.TabIndex = 3;
//
// label1
//
this.label1.Dock = System.Windows.Forms.DockStyle.Right;
this.label1.Location = new System.Drawing.Point(59, 4);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(63, 29);
this.label1.TabIndex = 1;
this.label1.Text = "label1";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lblBYear
//
this.lblBYear.Dock = System.Windows.Forms.DockStyle.Fill;
this.lblBYear.Location = new System.Drawing.Point(0, 4);
this.lblBYear.Name = "lblBYear";
this.lblBYear.Size = new System.Drawing.Size(59, 29);
this.lblBYear.TabIndex = 2;
this.lblBYear.Text = "label1";
this.lblBYear.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(3, 10);
this.numericUpDown1.Maximum = new decimal(new int[] {
9999,
0,
0,
0});
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(56, 19);
this.numericUpDown1.TabIndex = 3;
this.numericUpDown1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.numericUpDown1.Value = new decimal(new int[] {
2009,
0,
0,
0});
//
// YearMonthPacker
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Transparent;
this.Controls.Add(this.plBottom);
this.Controls.Add(this.plTop);
this.Name = "YearMonthPacker";
this.Size = new System.Drawing.Size(190, 59);
this.plTop.ResumeLayout(false);
this.plTop.PerformLayout();
this.plBottom.ResumeLayout(false);
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.plMiddle.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel plTop;
private ExtControls.ExtButton btnDropDown;
private System.Windows.Forms.Panel plBottom;
private System.Windows.Forms.TextBox txtYear;
private System.Windows.Forms.Label lblYear;
private System.Windows.Forms.TextBox txtMonth;
private System.Windows.Forms.Label lblMonth;
private System.Windows.Forms.Panel plMiddle;
private System.Windows.Forms.Panel panel2;
private ExtControls.ExtButton btnRight;
private System.Windows.Forms.Panel panel1;
private ExtControls.ExtButton btnLeft;
private System.Windows.Forms.Label lblBYear;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.NumericUpDown numericUpDown1;
}
你说的这种情况,没有现成的控件。你可以自己写一下,这个应该不难啊
CustomFormat 属性设置为 yyyy-MM
Format 设置为Custom