C#日历控件(MonthCalendar)

发布时间:2025-12-09 16:23:53 浏览次数:4

日历控件(MonthCalendar)用于显示日期,通常是与文本框联用,将日期控件中选择的日期添加到文本框中。

【实例】

             使用日历控件实现入职日期的选择。

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace MonthCalendarForm{public partial class Form1 : Form{public Form1(){InitializeComponent();}//窗体加载事件private void Form1_Load(object sender, EventArgs e){//隐藏日历控件monthCalendar1.Hide();}//“选择”按钮的单击事件private void button1_Click(object sender, EventArgs e){//显示日历控件monthCalendar1.Show();}//日历控件的日期改变事件private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e){//将选择的日期显示在文本框中textBox1.Text = monthCalendar1.SelectionStart.ToShortDateString();//隐藏日历控件monthCalendar1.Hide();} }}

                                               

                                     

                                     

需要做网站?需要网络推广?欢迎咨询客户经理 13272073477