日历控件(MonthCalendar)用于显示日期,通常是与文本框联用,将日期控件中选择的日期添加到文本框中。
【实例】
使用日历控件实现入职日期的选择。
using System; usiSEO靠我ng System.Collections.Generic; using System.ComponentModel; using System.Data; SEO靠我 using System.Drawing; using System.Linq; using System.Text; using System.SEO靠我Windows.Forms;namespace MonthCalendarForm {public partial class Form1 : Form{public Form1(){SEO靠我InitializeComponent();}//窗体加载事件private void Form1_Load(object sender, EventArgs e){//隐藏日历控件monthCaleSEO靠我ndar1.Hide();}//“选择”按钮的单击事件private void button1_Click(object sender, EventArgs e){//显示日历控件monthCalenSEO靠我dar1.Show();}//日历控件的日期改变事件private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs SEO靠我e){//将选择的日期显示在文本框中textBox1.Text = monthCalendar1.SelectionStart.ToShortDateString();//隐藏日历控件monthCalSEO靠我endar1.Hide();} } }网站备案号:浙ICP备17034767号-2