⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 Csharp实例编程百例.rar
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace testDateTimePickerApp
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Timer timer1;
		private System.Windows.Forms.DateTimePicker MyDTPicker;
		private System.Windows.Forms.MonthCalendar MyMCalendar;
		private System.Windows.Forms.CheckBox ckUpdate;
		private System.ComponentModel.IContainer components;

		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.MyDTPicker = new System.Windows.Forms.DateTimePicker();
			this.MyMCalendar = new System.Windows.Forms.MonthCalendar();
			this.timer1 = new System.Windows.Forms.Timer(this.components);
			this.ckUpdate = new System.Windows.Forms.CheckBox();
			this.SuspendLayout();
			// 
			// MyDTPicker
			// 
			this.MyDTPicker.CustomFormat = "yyyy-MM-dd hh:mm:ss tt";
			this.MyDTPicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
			this.MyDTPicker.Location = new System.Drawing.Point(16, 16);
			this.MyDTPicker.Name = "MyDTPicker";
			this.MyDTPicker.Size = new System.Drawing.Size(256, 21);
			this.MyDTPicker.TabIndex = 0;
			this.MyDTPicker.ValueChanged += new System.EventHandler(this.MyDTPicker_ValueChanged);
			// 
			// MyMCalendar
			// 
			this.MyMCalendar.AnnuallyBoldedDates = new System.DateTime[] {
																			 new System.DateTime(2003, 7, 1, 0, 0, 0, 0)};
			this.MyMCalendar.BoldedDates = new System.DateTime[] {
																	 new System.DateTime(2003, 7, 3, 0, 0, 0, 0)};
			this.MyMCalendar.Location = new System.Drawing.Point(8, 104);
			this.MyMCalendar.Name = "MyMCalendar";
			this.MyMCalendar.TabIndex = 1;
			this.MyMCalendar.TodayDate = new System.DateTime(2003, 7, 15, 0, 0, 0, 0);
			// 
			// timer1
			// 
			this.timer1.Interval = 1000;
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// ckUpdate
			// 
			this.ckUpdate.Location = new System.Drawing.Point(16, 64);
			this.ckUpdate.Name = "ckUpdate";
			this.ckUpdate.TabIndex = 3;
			this.ckUpdate.Text = "时间自动更新";
			this.ckUpdate.CheckedChanged += new System.EventHandler(this.ckUpdate_CheckedChanged);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(296, 261);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.ckUpdate,
																		  this.MyMCalendar,
																		  this.MyDTPicker});
			this.Name = "Form1";
			this.Text = "testDateTimerPicker";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void timer1_Tick(object sender, System.EventArgs e)
		{
			MyDTPicker.Value = DateTime.Now ;
		}

		private void MyDTPicker_ValueChanged(object sender, System.EventArgs e)
		{
			MyMCalendar.SetDate ( MyDTPicker.Value.Date );//更新MonthCalendar中的日期
		}

		private void ckUpdate_CheckedChanged(object sender, System.EventArgs e)
		{
			timer1.Enabled = ckUpdate.Checked ;
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -