4个回答
展开全部
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Winform
{
public class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
private void Form4_Load(object sender, EventArgs e)
{
//加载年 月 日 下拉框的值
for (int i = 1970; i < 2060; i++)
{
cboYear.Items.Add(i.ToString());
}
for (int j = 1; j < 13; j++)
{
cboMonth.Items.Add(j.ToString());
}
for (int k = 1; k < 32; k++)
{
cboDay.Items.Add(k.ToString());
}
//默认选中当天的日期
DateTime dt = DateTime.Today;
cboYear.SelectedItem = dt.Year.ToString();
cboMonth.SelectedItem = dt.Month.ToString();
cboDay.SelectedItem = dt.Day.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
monthCalendar1.Visible = true;
monthCalendar1.Focus();
}
private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
{
cboYear.SelectedItem = (e.End).Year.ToString();
cboMonth.SelectedItem = (e.End).Month.ToString();
cboDay.SelectedItem = (e.End).Day.ToString();
monthCalendar1.Visible = false;
}
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.cboYear = new System.Windows.Forms.ComboBox();
this.cboMonth = new System.Windows.Forms.ComboBox();
this.label13 = new System.Windows.Forms.Label();
this.label11 = new System.Windows.Forms.Label();
this.cboDay = new System.Windows.Forms.ComboBox();
this.label12 = new System.Windows.Forms.Label();
this.monthCalendar1 = new System.Windows.Forms.MonthCalendar();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// cboYear
//
this.cboYear.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboYear.FormattingEnabled = true;
this.cboYear.Location = new System.Drawing.Point(25, 33);
this.cboYear.Name = "cboYear";
this.cboYear.Size = new System.Drawing.Size(60, 20);
this.cboYear.TabIndex = 36;
//
// cboMonth
//
this.cboMonth.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboMonth.FormattingEnabled = true;
this.cboMonth.Location = new System.Drawing.Point(134, 33);
this.cboMonth.Name = "cboMonth";
this.cboMonth.Size = new System.Drawing.Size(60, 20);
this.cboMonth.TabIndex = 38;
//
// label13
//
this.label13.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label13.Location = new System.Drawing.Point(323, 36);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(45, 18);
this.label13.TabIndex = 41;
this.label13.Text = "日";
//
// label11
//
this.label11.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label11.Location = new System.Drawing.Point(97, 36);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(45, 18);
this.label11.TabIndex = 37;
this.label11.Text = "年";
//
// cboDay
//
this.cboDay.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboDay.FormattingEnabled = true;
this.cboDay.Location = new System.Drawing.Point(246, 32);
this.cboDay.Name = "cboDay";
this.cboDay.Size = new System.Drawing.Size(60, 20);
this.cboDay.TabIndex = 40;
//
// label12
//
this.label12.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label12.Location = new System.Drawing.Point(216, 36);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(45, 18);
this.label12.TabIndex = 39;
this.label12.Text = "月";
//
// monthCalendar1
//
this.monthCalendar1.Location = new System.Drawing.Point(257, 80);
this.monthCalendar1.Name = "monthCalendar1";
this.monthCalendar1.TabIndex = 42;
this.monthCalendar1.Visible = false;
this.monthCalendar1.DateSelected += new System.Windows.Forms.DateRangeEventHandler(this.monthCalendar1_DateSelected);
//
// button1
//
this.button1.Location = new System.Drawing.Point(67, 109);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 43;
this.button1.Text = "选择日期";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form4
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(579, 304);
this.Controls.Add(this.button1);
this.Controls.Add(this.monthCalendar1);
this.Controls.Add(this.cboYear);
this.Controls.Add(this.cboMonth);
this.Controls.Add(this.label13);
this.Controls.Add(this.label11);
this.Controls.Add(this.cboDay);
this.Controls.Add(this.label12);
this.Name = "Form4";
this.Text = "Form4";
this.Load += new System.EventHandler(this.Form4_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ComboBox cboYear;
private System.Windows.Forms.ComboBox cboMonth;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.ComboBox cboDay;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.MonthCalendar monthCalendar1;
private System.Windows.Forms.Button button1;
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Winform
{
public class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
private void Form4_Load(object sender, EventArgs e)
{
//加载年 月 日 下拉框的值
for (int i = 1970; i < 2060; i++)
{
cboYear.Items.Add(i.ToString());
}
for (int j = 1; j < 13; j++)
{
cboMonth.Items.Add(j.ToString());
}
for (int k = 1; k < 32; k++)
{
cboDay.Items.Add(k.ToString());
}
//默认选中当天的日期
DateTime dt = DateTime.Today;
cboYear.SelectedItem = dt.Year.ToString();
cboMonth.SelectedItem = dt.Month.ToString();
cboDay.SelectedItem = dt.Day.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
monthCalendar1.Visible = true;
monthCalendar1.Focus();
}
private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
{
cboYear.SelectedItem = (e.End).Year.ToString();
cboMonth.SelectedItem = (e.End).Month.ToString();
cboDay.SelectedItem = (e.End).Day.ToString();
monthCalendar1.Visible = false;
}
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.cboYear = new System.Windows.Forms.ComboBox();
this.cboMonth = new System.Windows.Forms.ComboBox();
this.label13 = new System.Windows.Forms.Label();
this.label11 = new System.Windows.Forms.Label();
this.cboDay = new System.Windows.Forms.ComboBox();
this.label12 = new System.Windows.Forms.Label();
this.monthCalendar1 = new System.Windows.Forms.MonthCalendar();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// cboYear
//
this.cboYear.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboYear.FormattingEnabled = true;
this.cboYear.Location = new System.Drawing.Point(25, 33);
this.cboYear.Name = "cboYear";
this.cboYear.Size = new System.Drawing.Size(60, 20);
this.cboYear.TabIndex = 36;
//
// cboMonth
//
this.cboMonth.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboMonth.FormattingEnabled = true;
this.cboMonth.Location = new System.Drawing.Point(134, 33);
this.cboMonth.Name = "cboMonth";
this.cboMonth.Size = new System.Drawing.Size(60, 20);
this.cboMonth.TabIndex = 38;
//
// label13
//
this.label13.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label13.Location = new System.Drawing.Point(323, 36);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(45, 18);
this.label13.TabIndex = 41;
this.label13.Text = "日";
//
// label11
//
this.label11.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label11.Location = new System.Drawing.Point(97, 36);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(45, 18);
this.label11.TabIndex = 37;
this.label11.Text = "年";
//
// cboDay
//
this.cboDay.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboDay.FormattingEnabled = true;
this.cboDay.Location = new System.Drawing.Point(246, 32);
this.cboDay.Name = "cboDay";
this.cboDay.Size = new System.Drawing.Size(60, 20);
this.cboDay.TabIndex = 40;
//
// label12
//
this.label12.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label12.Location = new System.Drawing.Point(216, 36);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(45, 18);
this.label12.TabIndex = 39;
this.label12.Text = "月";
//
// monthCalendar1
//
this.monthCalendar1.Location = new System.Drawing.Point(257, 80);
this.monthCalendar1.Name = "monthCalendar1";
this.monthCalendar1.TabIndex = 42;
this.monthCalendar1.Visible = false;
this.monthCalendar1.DateSelected += new System.Windows.Forms.DateRangeEventHandler(this.monthCalendar1_DateSelected);
//
// button1
//
this.button1.Location = new System.Drawing.Point(67, 109);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 43;
this.button1.Text = "选择日期";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form4
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(579, 304);
this.Controls.Add(this.button1);
this.Controls.Add(this.monthCalendar1);
this.Controls.Add(this.cboYear);
this.Controls.Add(this.cboMonth);
this.Controls.Add(this.label13);
this.Controls.Add(this.label11);
this.Controls.Add(this.cboDay);
this.Controls.Add(this.label12);
this.Name = "Form4";
this.Text = "Form4";
this.Load += new System.EventHandler(this.Form4_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ComboBox cboYear;
private System.Windows.Forms.ComboBox cboMonth;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.ComboBox cboDay;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.MonthCalendar monthCalendar1;
private System.Windows.Forms.Button button1;
}
}
推荐于2017-09-20 · 知道合伙人互联网行家
关注
展开全部
textBox1.Text = monthCalendar1.SelectionStart.ToString("yyyyMMdd");
这个是显示选中日期的开始时间,如果是点击的话,就是这个语句就好。
如果是拖动选择日期段的话,这个是开始日期,
结束日期是
textBox1.Text = monthCalendar1.SelectionEnd.ToString("yyyyMMdd");
这个是显示选中日期的开始时间,如果是点击的话,就是这个语句就好。
如果是拖动选择日期段的话,这个是开始日期,
结束日期是
textBox1.Text = monthCalendar1.SelectionEnd.ToString("yyyyMMdd");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
date=this.monthcalendar1.SelectionStart.toString();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
SelectionStart SelectionEnd试下这两个属性
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询