110,538
社区成员
发帖
与我相关
我的任务
分享
#region WinForm中日期控件开窗
private void button3_Click(object sender, EventArgs e)
{
string tDateTime = string.Empty;
NewOpenManager1.OpenWindow(ref tDateTime);//調用OpenWindow得到回傳的日期
if (tDateTime == null)
{
}
else
{
this.textBox4.Text = tDateTime;
}
}
public abstract class NewOpenManager1
{
public static void OpenWindow(ref string tDateTime)
{
DateTime frmDt = new DateTime();
tDateTime = frmDt.GetNewWindowDateTime();----这里出错
}
}
public string tDateTime
{
get;
set;
}
public string GetNewWindowDateTime()
{
switch (ShowDialog())
{
case DialogResult.OK:
return this.tDateTime;
default:
break;
}
return null;
}
private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
{
String tDate = this.monthCalendar1.SelectionStart.ToString("yyyy-MM-dd");---这里出错
this.tDateTime = tDate.Replace("-", "/");
this.DialogResult = DialogResult.OK;
}
#endregion
private void button8_Click(object sender, EventArgs e)
{
string tDateTime = string.Empty;
monthCalendar1.Visible = true;
}
private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
{
String tDate = this.monthCalendar1.SelectionStart.ToString("yyyy-MM-dd");
monthCalendar1.Visible = false;
}
先让月历不显示
这样用,多方便
你把值设置成全局变量就行
tDateTime = frmDt.GetNewWindowDateTime();
这句直接就出错误了,编译都不行
String tDate = this.monthCalendar1.SelectionStart.ToString("yyyy-MM-dd");
MessageBox.Show(tDate);
我测试了,没有提示错误,是不是你中间有什么问题