c# Winform 只有年份和月份 的时间控件 10

有没有这种控件,类似DateTimePacker的但是只能选择年份和月份,不显示具体是哪天的,有什么好的解决办法告诉我啊。谢谢啊,解决的+50分... 有没有这种控件,类似DateTimePacker 的 但是只能选择年份和月份,不显示具体是哪天的,有什么好的解决办法 告诉我啊。
谢谢啊 ,解决的 +50分
展开
 我来答
finalyfantasy
2009-10-22 · TA获得超过1364个赞
知道小有建树答主
回答量:1631
采纳率:0%
帮助的人:581万
展开全部

没有现成的,用自定义控件,界面按照下面布置就可以了,没时间作,只画了一下界面,

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;

    }

火沙
2009-10-22 · TA获得超过954个赞
知道小有建树答主
回答量:478
采纳率:0%
帮助的人:400万
展开全部
DateTimePacker 可以让它只显示年月,但是下拉还是有日。
你说的这种情况,没有现成的控件。你可以自己写一下,这个应该不难啊
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
LK_soso
2009-10-22 · TA获得超过278个赞
知道小有建树答主
回答量:351
采纳率:0%
帮助的人:191万
展开全部
用2个下拉菜单控件combox好像是这个,提前把年和月添加进去就行了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
itliyi
2009-10-22 · 超过32用户采纳过TA的回答
知道答主
回答量:127
采纳率:0%
帮助的人:70.4万
展开全部
可以直接用DateTimePicker控件
CustomFormat 属性设置为 yyyy-MM
Format 设置为Custom
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式