当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 可用来显示空值的时间选择控件3

ASP.NET
asp.net下将图片保存到XML文件的方法
asp.net 通过aspnetpager为DataList分页
Asp.Net 动态页面转静态页面主要代码
asp.net下检测远程URL是否存在的三种方法
asp.net(C#)把汉字转化成全拼音函数(全拼)
asp.net下xml当作导航数据源实现动态权限
asp.net Cookie操作类
先装VS再装IIS时出错的解决方法
asp.net 选择excel类型文件,利用Dos命令成批复制文件
Asp.net XML文档进行添加删改操作的实例代码
ASP.NET 页面间数据传递方法小结
asp.net 文件上传与刷新与asp.net页面与iframe之间的数据传输
asp.net Urlrewriter在虚拟主机上的使用方法
Repeater的FooterTemplate中控件内容设置方法
asp.net(c#)做一个网页数据采集工具
ASP.NET调用javascript脚本的常见方法小结
asp.net AutoCompleteExtender的一个简单例子代码
asp.net 光棒效应实现代码
asp.net 数据访问层 存储过程分页语句
Asp.Net Oracle数据的通用操作类

ASP.NET 中的 可用来显示空值的时间选择控件3


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 32 ::
收藏到网摘: n/a

public DateInput() { // 该调用是 Windows.Forms 窗体设计器所必需的。 InitializeComponent(); tbMonth.ContextMenu = mnu ; tbYear.ContextMenu = mnu ; tbDay.ContextMenu = mnu ; this.Height = 21 ; this.Value = DateTime.Now ; this.DateFormat = "yyyy-MM-dd" ; if (!this.DesignMode) CreateCalendar() ; this.UpDown.Width = 16 ; this.Refresh() ; } private void CreateCalendar() { Calendar = new MonthCalendar() ; Calendar.Visible = true ; Calendar.DateSelected+=new DateRangeEventHandler(Calendar_DateSelected); frmCalendar = new Form() ; frmCalendar.FormBorderStyle = FormBorderStyle.None ; frmCalendar.TopMost = true ; frmCalendar.Width = 270 ; frmCalendar.Height = 145 ; frmCalendar.Controls.Add(Calendar) ; Calendar.Dock = DockStyle.Fill ; frmCalendar.StartPosition = FormStartPosition.Manual ; frmCalendar.Deactivate+=new EventHandler(Calendar_Leave); frmCalendar.ShowInTaskbar = false ; } private void Calendar_DateSelected(object sender, System.Windows.Forms.DateRangeEventArgs e) { this.frmCalendar.Hide() ; this.Value = this.Calendar.SelectionStart ; this.tbDay.Focus() ; } private void Calendar_Leave(object sender, System.EventArgs e) { this.frmCalendar.Hide() ; //this.Value = this.Calendar.SelectionStart ; this.tbDay.Focus() ; } private void RefreshDisplay() { bool blGB = false ; string strChar = "" ; if (strDateFormat == "yyyy-MM-dd") strChar = "-" ; else if (strDateFormat == "yyyy.MM.dd") strChar = "." ; else if (strDateFormat == "yyyy/MM/dd") strChar = "/" ; else if (strDateFormat== "yyyy年MM月dd日") blGB = true ; else strChar = strFomatChar ; if (blGB) { lbSep1.Text = "年" ; lbSep2.Text = "月" ; lbSep3.Text = "日" ; } else { lbSep1.Text = strChar ; lbSep2.Text = strChar ; lbSep3.Text = "" ; } this.Refresh() ; } /// /// 是不是空值 /// public bool IsNull() { String strYear = tbYear.Text ; String strMonth = tbMonth.Text ; String strDay = tbDay.Text ; if (strYear == "" ||strMonth == "" ||strDay == "" ) return true ; else return false ; } /// /// 设置值为空(实际为时间的最小值) /// public void SetValueNull() { this.Value = DateTime.MinValue ; } /// /// 清空输入值 /// private void EmptyInput() { tbYear.Text = "" ; tbMonth.Text = "" ; tbDay.Text = "" ; } private int GetThisMonthMaxDay() { int Year = int.Parse(tbYear.Text) ; int Month = int.Parse(tbMonth.Text) ; switch(Month) { case 2: if (DateTime.IsLeapYear(Year))//闰年 return 29 ; else return 28 ; case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31 ; case 4: case 6: case 9: case 11: return 30 ; default: return 31 ; } } private void SetRightFmt() { if (IsNull()) EmptyInput() ; else { SetRightMonthDay() ; } this.Refresh() ; } private void SetRightMonthDay() { int MaxDay = GetThisMonthMaxDay() ; int Day = int.Parse(tbDay.Text) ; if (Day > MaxDay) tbDay.Text = MaxDay.ToString() ; } private void IncDecDate(int iSign) { string strYear = tbYear.Text ; if (strYear == "") strYear = DateTime.Now.Year.ToString() ; string strMonth = tbMonth.Text ; if (strMonth == "") strMonth = DateTime.Now.Month.ToString() ; string strDay = tbDay.Text ; if (strDay == "") strDay = DateTime.Now.Day.ToString() ; string strDate = strYear +"-"+ strMonth +"-" +strDay ; DateTime dtOld = DateTime.Parse(strDate) ; if (tbYear.Focused) { this.Value = dtOld.AddYears(1*iSign) ; } else if (tbMonth.Focused) { this.Value = dtOld.AddMonths(1*iSign) ; } else { this.Value = dtOld.AddDays(1*iSign) ; } } private Form GetWindow() { Control con = this ; while(!(con.Parent is Form)) con = con.Parent ; return (Form)con.Parent ; } /// /// 清理所有正在使用的资源。 /// protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); }