可用來顯示空值的時間選擇控制項2

來源:互聯網
上載者:User
控制項|顯示 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




相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。