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

王朝c#·作者佚名  2006-12-17
窄屏简体版  字體: |||超大  

using System;

using System.Collections;

using System.ComponentModel;

using System.Drawing;

using System.Data;

using System.Windows.Forms;

namespace XPangLib

{

/// <summary>

/// DateInput 的摘要说明。

/// </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

/// <summary>

/// 必需的设计器变量。

/// </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 ;

/// <summary>

/// 选定的日期

/// </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() ;

}

}

#endregion

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航