首页 > 编程 > .NET > 正文

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

2024-07-10 13:03:57
字体:
来源:转载
供稿:网友
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();
        }


        /// <summary>
        /// 获取所有system.globalization.cultureinfo支持的文化语言,并
        /// 将国家的名称填充到“语言类型”。以当前环境的文化语言为默认
        /// cultureinfo对象。
        /// </summary>
        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;
        }

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表