![](/img/trans.png)
[英]C# web form - Looking to get the date of the first monday of the month after the selected date from the calendar
[英]Get Date in Text Box from month calendar with button in c#
我想在單擊窗口表單的按鈕后在文本框中使用月份日歷日期。 打開表單時,日歷應隱藏,單擊按鈕后,日歷將可見。
我在Visual Studio 2008中使用c#,因此請根據此工具給我答復。
為此使用DateTimePicker類。 它完全具有您描述的行為。
嘗試使用Control.Show()
方法和Control.Visible
屬性:
private MonthCalendar _monthCalendar;
public Form1()
{
InitializeComponent();
// invisible on startup
_monthCalendar.Visible = false;
_monthCalendar.MaxSelectionCount = 1;
}
private void button1_Click(object sender, EventArgs e)
{
//show when needed
_monthCalendar.Show();
}
private void textBox1_Enter(object sender, EventArgs e)
{
_monthCalendar.Show();
}
private void textBox1_Leave(object sender, EventArgs e)
{
if (!_monthCalendar.Focused)
_monthCalendar.Visible = false;
}
private void monthCalendar_DateSelected(object sender, DateRangeEventArgs e)
{
var monthCalendar = sender as MonthCalendar;
textBox1.Text = monthCalendar.SelectionStart.ToString();
}
private void monthCalendar_Leave(object sender, EventArgs e)
{
var monthCalendar = sender as MonthCalendar;
monthCalendar.Visible = false;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.