1.把TextBox和MonthCalendar控件拖到界面上。
2.将MonthCalendar控件的Visible属性设为False.
3.在代码里写下下面的内容:
private void textBox1_Click(object sender, EventArgs e)
{
monthCalendar1.Visible = true;
monthCalendar1.Focus();
}
private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{
textBox1.Text = e.Start.ToString("yyyy-MM-dd");
}
private void monthCalendar1_Leave(object sender, EventArgs e)
{
monthCalendar1.Visible = false;
}