可用来显示空值的时间选择控件2

using System;

using System.Collections;

using System.ComponentModel;

using System.Drawing;

using System.Data;

using System.Windows.Forms;

namespace XPangLib

{

///

1<summary>
2
3///  DateInput 的摘要说明。 
4
5///  </summary>

public class DateInput : System.Windows.Forms.UserControl

{

#region 成员控件

private System.Windows.Forms.MonthCalendar Calendar ;

private System.Windows.Forms.Form frmCalendar ;

private System.Windows.Forms.Panel panel3;

private System.Windows.Forms.Button btnMain;

private System.Windows.Forms.VScrollBar UpDown;

private System.Windows.Forms.Panel panel1;

private System.Windows.Forms.Panel panel2;

private System.Windows.Forms.Label lbSep3;

private System.Windows.Forms.TextBox tbDay;

private System.Windows.Forms.Label lbSep2;

private System.Windows.Forms.TextBox tbMonth;

private System.Windows.Forms.Label lbSep1;

private System.Windows.Forms.TextBox tbYear;

private System.Windows.Forms.Label label2;

private System.Windows.Forms.Label lbSpace;

#endregion

///

1<summary>
2
3///  必需的设计器变量。 
4
5///  </summary>

private System.ComponentModel.Container components = null ;

private ContextMenu mnu = new ContextMenu() ;

#region 自定义属性

[Browsable( true ),ReadOnly( false )]

public Size Size

{

set

{

base .Size = new Size( value .Width,21) ;

this .SetBounds( base .Location.X, base .Location.Y, this .Width, base .Height) ;

this .Refresh() ;

}

get

{

return base .Size ;

}

}

private string strDateFormat ;

[CategoryAttribute("显示属性和值"),

TypeConverterAttribute( typeof (DateFormatConverter)),

DescriptionAttribute("时间显示格式"),

ReadOnlyAttribute( false )]

public string DateFormat

{

get

{

return strDateFormat ;

}

set

{

strDateFormat = value ;

RefreshDisplay() ;

}

}

private string strFomatChar ;

[CategoryAttribute("显示属性和值"),

DescriptionAttribute("自定义显示格式"),

ReadOnlyAttribute( false )]

public string FomatChar

{

get

{

return strFomatChar ;

}

set

{

strFomatChar = value ;

RefreshDisplay() ;

}

}

bool blShowUpDown = false ;

[CategoryAttribute("显示属性和值"),

DescriptionAttribute("显示UpDown按钮"),

ReadOnlyAttribute( false )]

public bool ShowUpDown

{

get

{

return blShowUpDown ;

}

set

{

blShowUpDown = value ;

this .btnMain.Visible = ! value ;

this .UpDown.Visible = value ;

}

}

private DateTime dtValue ;

///

1<summary>
2
3///  选定的日期 
4
5///  </summary>

[CategoryAttribute("显示属性和值"),

DescriptionAttribute("选定的值"),

ReadOnlyAttribute( false )]

public DateTime Value

{

get

{

if (IsNull())

dtValue = DateTime.MinValue ;

else

{

string strYear = tbYear.Text ;

string strMonth = tbMonth.Text ;

string strDay = tbDay.Text ;

string strDate = strYear +"-"+ strMonth +"-" +strDay ;

dtValue = DateTime.Parse(strDate) ;

}

return dtValue ;

}

set

{

dtValue = value ;

if (dtValue == DateTime.MinValue)

EmptyInput() ;

else

{

tbYear.Text = dtValue.Year.ToString() ;

tbMonth.Text = dtValue.Month.ToString() ;

tbDay.Text = dtValue.Day.ToString() ;

}

this .Refresh() ;

}

}

<SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times Ne

Published At
Categories with Web编程
Tagged with
comments powered by Disqus