C # multiple textbox controls call the same monthcalendar input date: the code is as follows:
You need to add the textbox1 + textbox2 + monthcalendar1 Control
Datetime firstclick;
Int textboxnumber;
Private void textbox#click (Object sender, eventargs E)
{
This. textboxnumber = 1;
This. monthcalendar1.visible = true;
}
Private void textbox2_click (Object sender, eventargs E)
{
This. textboxnumber = 2;
This. monthcalendar1.visible = true;
}
/// <Summary>
/// Date control call Function
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void monthcalendar1_dateselected (Object sender, daterangeeventargs E)
{
If (this. textboxnumber = 1)
{
Monthcalendardoubleclick (this. textbox1, this. monthcalendar1 );
}
Else
{
Monthcalendardoubleclick (this. textbox2, this. monthcalendar1 );
}
}
/// <Summary>
/// Double-click the date control to call the Function
/// </Summary>
/// <Param name = "selectedtextbox"> </param>
/// <Param name = "monthcalendar"> </param>
Private void monthcalendardoubleclick (textbox selectedtextbox, monthcalendar)
{
Datetime secondclick = datetime. Now; // record the second click time;
String clickspan = convert. tostring (secondclick-firstclick); // calculate the interval between two clicks. Format: 00: 00: 00.1875000
String separator = ":.";
Char [] charclickspan = separator. tochararray ();
String [] arrayclickspan = clickspan. Split (charclickspan );
If (arrayclickspan. length = 4 & arrayclickspan [0]. equals ("00") & arrayclickspan [1]. equals ("00") & arrayclickspan [2]. equals ("00 "))
{
If (convert. toint32 (arrayclickspan [3]. substring (0, 3)> systeminformation. doubleclicktime) // If the interval between two clicks is greater than the system double-click time;
{
Firstclick = secondclick; // assign the second click Time to the first time;
}
Else
{
// The interval between two clicks is less than or equal to the time when you double-click
Selectedtextbox. Text = monthcalendar. selectionstart. tostring ("yyyy-mm-dd"); // double-click the selected text to the textbox;
This. monthcalendar1.visible = false;
}
}
Else
{
Firstclick = secondclick;
}
}