C# code
private void textBox1_MouseDown(object sender, MouseEventArgs e)
{
MonthCalendar ms = new MonthCalendar();
this.Controls.Add(ms);
ms.DateChanged += new DateRangeEventHandler(ms_DateChanged);
}
void ms_DateChanged(object sender, DateRangeEventArgs e)
{
this.textBox1.Text = e.Start.Date.ToString();
}
private void textBox1_MouseClick(object sender, MouseEventArgs e)
{
monthCalendar1.Visible = true;
}
private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
{
textBox1.Text= monthCalendar1.SelectionStart.ToString();
monthCalendar1.Visible = false;
}
这个是不可以复制的,你要找到那个事件才得啊,你单击monthCalendar1控件,在它的事件那里找到DateSelected双击它,然后就出来private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
{ } 这个东西,你就在里面加textBox1.Text= monthCalendar1.SelectionStart.ToString();
monthCalendar1.Visible = false;
事件请自己在属性那栏里添加啦!!
测试可以实现你说的功能啊
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 日期控件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_MouseClick(object sender, MouseEventArgs e)
{
if (this.monthCalendar1.Visible == false)
{ this.monthCalendar1.Visible = true; }
else
{
this.monthCalendar1.Visible = false;
}
}
private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
{
string DateTime=this.monthCalendar1.SelectionStart.ToString();
this.textBox1.Text = DateTime;
this.monthCalendar1.Visible = false;
}
}
}