繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> 组件控件开发 >> 刚写好的Asp.Net时间和日期的Label控件。作为讲解Asp.net控件开发的第一部分:继承开发(5-2)

刚写好的Asp.Net时间和日期的Label控件。作为讲解Asp.net控件开发的第一部分:继承开发(5-2)

2004-10-01 08:26:10  作者:  来源:互联网  浏览次数:24  文字大小:【】【】【
简介:public DateTimePickEditor()         {             //        &...

public DateTimePickEditor()

{

//

// Windows 窗体设计器支持所必需的

//

try

{

InitializeComponent();

}

catch(Exception ee)

{

MessageBox.Show(ee.Message+"\n"+ee.Source);

}

//

// TODO: 在 InitializeComponent 调用后添加任何构造函数代码

//

// this.Show();

}

private void btnCancel_Click(object sender, System.EventArgs e)

{

this.Close();

}

///

/// 获取所有System.Globalization.CultureInfo支持的文化语言,并

/// 将国家的名称填充到“语言类型”。以当前环境的文化语言为默认

/// CultureInfo对象。

///

void FullcbCultrues()

{

//清除所有“语言类型”的所有内容

if(this.cbCultures.Items.Count>0)

this.cbCultures.Items.Clear();

//

//获取所有System.Globalization.CultureInfo支持的文化语言,并将国家的名称填充到“语言类型”。

foreach(CultureInfo country in CultureInfo.GetCultures(CultureTypes.SpecificCultures))

{

this.curi = new zyqCultrueInfo(country.Name);

if (!this.cbCultures.Items.Contains(curi))

{

this.cbCultures.Items.Add(this.curi);

}

}

cbCultures.Items.Add(new zyqCultrueInfo(CultureInfo.InvariantCulture.Name));

//选定获取当前以当前环境的文化语言的索引值

if(this._dtf.LanguageAndCountry==null)

this.cbCultures.SelectedIndex =this.cbCultures.FindStringExact(CultureInfo.CurrentCulture.DisplayName);

else

{

this.curi= new zyqCultrueInfo(this._dtf.LanguageAndCountry);

this.cbCultures.SelectedIndex=this.cbCultures.FindStringExact(this.curi.DisplayName);

}

}

private void cbCultures_SelectedIndexChanged(object sender, System.EventArgs e)

{

this.curi = (zyqCultrueInfo)this.cbCultures.SelectedItem;

//RFC 1766 name

this.txtName.Text =curi.Name;

//日历

if(this.cbOptionalCalendars.Items.Count >0)

this.cbOptionalCalendars.Items.Clear();

foreach(Calendar cal in this.curi.OptionalCalendars)

{

if(!this.cbOptionalCalendars.Items.Contains(cal))

this.cbOptionalCalendars.Items.Add(cal);

}

int i = this.cbOptionalCalendars.SelectedIndex = this.cbOptionalCalendars.Items.IndexOf(this.curi.Calendar);

// //分隔符

this.txtDateSeparator.Text = this.curi.DateTimeFormat.DateSeparator;

this.txtTimeSeparator.Text = this.curi.DateTimeFormat.TimeSeparator;

this.txtAM.Text =this.curi.DateTimeFormat.AMDesignator;

this.txtPM.Text = this.curi.DateTimeFormat.PMDesignator;

//日期和时间格式:

this.cbFormate.Items.Clear();

foreach(string s in this.curi.DateTimeFormat.GetAllDateTimePatterns())

{

if(!this.cbFormate.Items.Contains(s))

this.cbFormate.Items.Add(s);

}

int x=0;

if(this._dtf.FormateString!=null)

x=this.cbFormate.FindStringExact(this.curi.DateTimeFormat.FullDateTimePattern);

if(x>0)

this.cbFormate.SelectedIndex =x;

else

this.cbFormate.SelectedIndex = this.cbFormate.FindStringExact(this.curi.DateTimeFormat.FullDateTimePattern);

}

private void cbOptionalCalendars_SelectedIndexChanged(object sender, System.EventArgs e)

{

// cbCultures_SelectedIndexChanged (sender, e);

}

private void cbFormate_TextChanged(object sender, System.EventArgs e)

{

this.txtFormat.Text = this.cbFormate.Text;

}

private void txtFormat_TextChanged(object sender, System.EventArgs e)

{

try

{

//this._dtf = this.txtFormat.Text;

this.lblExmple.Text = DateTime.Now.ToString(this.txtFormat.Text, curi.DateTimeFormat);;

}

catch(Exception de)

{

MessageBox.Show(de.Message,"Wrong");

}

}

private void cbShortLongDatePattern_TextChanged(object sender, System.EventArgs e)

{

string wrd="";

string sel="";

switch(this.cbShortLongDatePattern.Text)

{

case "ShortDate":

wrd="d";

sel=this.curi.DateTimeFormat.ShortDatePattern;

break;

case "LongDate":

wrd="D";

sel=this.curi.DateTimeFormat.LongDatePattern;

break;

case "FullDate":

wrd="f/F";

sel=this.curi.DateTimeFormat.FullDateTimePattern;

break;

case "RFC1123":

wrd="r/R";

sel=this.curi.DateTimeFormat.RFC1123Pattern;

break;

case "ISO8601":

wrd="s";

sel=this.curi.DateTimeFormat.SortableDateTimePattern;

break;

case "UniversalSortableDateTime":

wrd="u/U";

//sel=this.curi.DateTimeFormat.ShortDatePattern;

break;

case "ShortTime":

wrd="t";

sel=this.curi.DateTimeFormat.ShortTimePattern;

break;

case "LongTime":

wrd="T";

sel=this.curi.DateTimeFormat.LongTimePattern;

break;

case "YearMonth":

wrd="y/Y";

sel=this.curi.DateTimeFormat.YearMonthPattern;

break;

default:

wrd="g/G";

//sel=this.curi.DateTimeFormat.ShortDatePattern;

break;

}

char[] sp=new char[]{'/'};

string[] ss=wrd.Split(sp);

this.cbFormate.Items.Clear();

//DateTimeFormatInfo _dateTimeFormatInfo=new DateTimeFormatInfo();

for(int i=0;i<=(ss.Length-1);i++)

{

foreach(string s in this.curi.DateTimeFormat.GetAllDateTimePatterns(Convert.ToChar(ss[i])))

{

if(!this.cbFormate.Items.Contains(s))

this.cbFormate.Items.Add(s);

}

if(!sel.Equals(string.Empty))

this.cbFormate.SelectedIndex = this.cbFormate.FindStringExact(sel);

else

this.cbFormate.SelectedIndex=0;

}

}

private void zyqDateTimePickEditor_Load(object sender, System.EventArgs e)

{

this.FullcbCultrues();

this.cbShortLongDatePattern.SelectedIndex =0;

}

private void btnOK_Click(object sender, System.EventArgs e)

{

if((!this.txtName.Text.Equals(string.Empty)) && (!this.txtFormat.Text.Equals(string.Empty)))

if((!this.txtName.Text.Equals(this._dtf.LanguageAndCountry))&& (!this.txtFormat.Text.Equals(this._dtf.FormateString)))

{

//根据设置一定要生成一个新的对象才能在页面上产生相应的变化

this._dtf= new DTFormatSetting(this.txtFormat.Text,this.txtName.Text);

}

this.DialogResult = DialogResult.OK;

this.Close();

}

private void txtName_TextChanged(object sender, System.EventArgs e)

{

// if(!this.txtName.Text.Equals(string.Empty))

// if(!this.txtName.Text.Equals(this._dtf.LanguageAndCountry))

// this._dtf.LanguageAndCountry =this.txtName.Text;

}

责任编辑:admin
相关文章