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

ASP.NET
asp.net下用服务器端代码解决浏览器兼容性问题
asp.net 安全的截取指定长度的html或者ubb字符串
asp.net 在线编辑word文档 可保存到服务器
asp.net 提高网站速度及如何利用缓存
asp.net 修改/删除站内目录操作后Session丢失问题
asp.net URL重写简化版 速学URL重写
asp.net EncryptHelper 加密帮助类
asp.net JSONHelper JSON帮助类
C# 调用存储过程简单完整的实例代码
vs2008 安装失败的总结与分享
HttpHandler HttpModule入门篇
ASP.NET(AJAX+JSON)实现对象调用
Asp.net 基于Cookie简易的权限判断
asp.net通过HttpModule自动在Url地址上添加参数
asp.net 字符串、二进制、编码数组转换函数
ASP.NET操作Excel备忘录
记录游客页面访问IP的简易实现代码 (asp.net+txt)
比较简单的将数据信息导入wrod文档方案(C# for word)
增加asp.net应用程序性能的20种方法(简单有效)
ASP.NET 图片防盗链的实现原理分析

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 31 ::
收藏到网摘: 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 ); }