根据瘦子的日历,改装了一个月历控件

2.GIF 3.GIF
脚本下载

  1 using  System;
  2 using  System.Web;
  3 using  System.Web.UI;
  4 using  System.Web.UI.WebControls;
  5 using  System.ComponentModel;
  6 using  System.Drawing;
  7 using  System.Drawing.Design;
  8 using  System.Reflection;
  9 using  System.Globalization;
 10 using  System.Collections;
 11 using  System.Text;
 12 namespace  Kkding.Web.UI.WebControls
 13 {
 14    /// <summary>
 15    /// Month 的摘要说明。
 16    /// </summary>

 17    [
 18    //DefaultEvent("DateChanged"),
 19    DefaultProperty("Text"),
 20    Designer(typeof(MonthChooserDesigner)),
 21    //ValidationProperty("SelectedDateText"),
 22    ToolboxData("<{0}:MonthChooser runat=\"server\"></{0}:MonthChooser>"),
 23    ToolboxBitmap(typeof(System.Web.UI.WebControls.Calendar))
 24    ]
 25    public class MonthChooser : WebControl
 26    {
 27        private const string MONTHCSS = "MonthCSS";
 28        private TextBox _MonthTextBox;
 29        [
 30        NotifyParentProperty(true),
 31        Bindable(true),
 32        Category("Behavior"),
 33        Description("设置当前选择的日期。日期选择器只支持从1745-1到9998之间的日期,此范围之外的日期请手工输入。")
 34        ]
 35        public string Text
 36        {
 37            get
 38            {
 39                return _MonthTextBox.Text;
 40            }

 41            set
 42            {
 43                _MonthTextBox.Text = value;
 44            }

 45        }

 46        [
 47        Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),EditorBrowsable(EditorBrowsableState.Never)
 48        ]
 49        public override Unit Width
 50        {
 51            get
 52            {
 53                return Unit.Empty;
 54            }

 55            set
 56            {
 57            }

 58        }

 59        [
 60        Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),EditorBrowsable(EditorBrowsableState.Never)
 61        ]
 62        public override Unit Height
 63        {
 64            get
 65            {
 66                return Unit.Empty;
 67            }

 68            set
 69            {
 70            }

 71        }

 72
 73        public MonthChooser():base(HtmlTextWriterTag.Unknown)
 74        {
 75            
 76            _MonthTextBox = new TextBox();
 77            //
 78            // TODO: 在此处添加构造函数逻辑
 79            //
 80        }

 81        
 82        protected override void OnInit(EventArgs e)
 83        {
 84            
 85            _MonthTextBox.EnableViewState = true;
 86            Controls.Add(_MonthTextBox);
 87            base.OnInit (e);
 88        }

 89
 90        
 91        protected override void Render(HtmlTextWriter writer) 
 92        {
 93            //if(!Page.IsClientScriptBlockRegistered(MONTHCSS))
 94            //{
 95            //    this.Page.RegisterStartupScript(MONTHCSS,"");
 96                writer.AddAttribute(HtmlTextWriterAttribute.Href ,"/aspnet_client/kkding/MonthChooser.css");
 97                writer.AddAttribute(HtmlTextWriterAttribute.Type , "text/css");
 98                writer.AddAttribute("rel" , "stylesheet");
 99                writer.RenderBeginTag("link");
100                writer.RenderEndTag();
101            //}
102
103            writer.AddAttribute("name",this.ID);
104            writer.AddAttribute(HtmlTextWriterAttribute.Class,"month");
105            writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding,"0");
106            writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing,"1");
107            writer.AddStyleAttribute("Behavior","url('/aspnet_client/kkding/MonthChooser.htc')");
108            //writer.AddStyleAttribute("width","80px");
109            //writer.AddStyleAttribute("BORDER","#abc1f4 1px solid");
110            writer.RenderBeginTag(HtmlTextWriterTag.Table);
111            _MonthTextBox.Style.Add("BORDER","0");
112            _MonthTextBox.Width = 50;
113            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
114            writer.AddAttribute(HtmlTextWriterAttribute.Rowspan,"2");
115            writer.AddAttribute(HtmlTextWriterAttribute.Class,"tddropdown");
116            writer.RenderBeginTag(HtmlTextWriterTag.Td);
117            writer.RenderEndTag();
118            writer.AddAttribute(HtmlTextWriterAttribute.Rowspan,"2");
119            writer.AddAttribute(HtmlTextWriterAttribute.Class,"tdtext");
120            writer.RenderBeginTag(HtmlTextWriterTag.Td);
121            //writer.RenderBeginTag(HtmlTextWriterTag.Div);
122            _MonthTextBox.RenderControl(writer);
123            writer.RenderEndTag();
124            writer.AddAttribute(HtmlTextWriterAttribute.Class,"tdup");
125            writer.RenderBeginTag(HtmlTextWriterTag.Td);
126            writer.RenderEndTag(); // td
127            writer.RenderEndTag(); // tr
128            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
129            writer.AddAttribute(HtmlTextWriterAttribute.Class,"tddown");
130            writer.RenderBeginTag(HtmlTextWriterTag.Td);
131            writer.RenderEndTag(); // td
132            writer.RenderEndTag(); // tr
133            writer.RenderEndTag(); // table
134            //writer.RenderEndTag();
135        }

136
137    }

138}

139


using  System;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.Design;
using  System.ComponentModel.Design;
using  System.ComponentModel;
using  System.Windows.Forms;
namespace  Kkding.Web.UI.WebControls
{
    
/// <summary>
    
/// MonthDesigner 的摘要说明。
    
/// </summary>

    public class MonthChooserDesigner : ControlDesigner
    
{
        
public override void Initialize(IComponent component)
        
{
            
base.Initialize(component);
        }


        
public override String GetDesignTimeHtml()
        
{
            
if ((base.Component == null|| !(base.Component is MonthChooser))
            
{
                
return "Error Month";
            }

            
string result = "";
            
try
            
{
                MonthChooser month 
= (MonthChooser) base.Component;
                result 
= @"<TABLE id='monthMain' style='BORDER-RIGHT: #abc1f4 1px solid; BORDER-TOP: #abc1f4 1px solid;  BORDER-LEFT: #abc1f4 1px solid; BORDER-BOTTOM: #abc1f4 1px solid'
                borderColor='#abc1f4' cellSpacing='1' cellPadding='0' name='Month'>
                    <TR>
                        <TD style='BORDER-RIGHT: #abc1f4 1px solid; BORDER-TOP: #abc1f4 1px solid; FONT-SIZE: 1px; BORDER-LEFT: #abc1f4 1px solid; BORDER-BOTTOM: #abc1f4 1px solid; BACKGROUND-COLOR: #c5d5fc'
                            align='center' width='13'><IMG src='/aspnet_client/kkding/dropdown.gif' align='middle' border='0'></TD>
                        <TD><INPUT  style='BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; FLOAT: left; BORDER-BOTTOM-WIDTH: 0px; WIDTH: 50px; BORDER-RIGHT-WIDTH: 0px'
                                value='{0}'></TD>
                        <TD width='15' height='100%'>
                            <TABLE height='100%' cellSpacing='0' cellPadding='0' width='100%'
                                border='0'>
                                    <TR>
                                        <TD style='BORDER-RIGHT: #abc1f4 1px solid; BORDER-TOP: #abc1f4 1px solid; BORDER-LEFT: #abc1f4 1px solid; BORDER-BOTTOM: #abc1f4 1px solid; BACKGROUND-COLOR: #c5d5fc'
                                            align='center' width='15' height='50%'><IMG src='/aspnet_client/kkding/up.gif' align='middle' border='0'></TD>
                                    </TR>
                                    <TR>
                                        <TD style='BORDER-RIGHT: #abc1f4 1px solid; BORDER-TOP: #abc1f4 1px solid; BORDER-LEFT: #abc1f4 1px solid; BORDER-BOTTOM: #abc1f4 1px solid; BACKGROUND-COLOR: #c5d5fc'
                                            align='center' width='15' height='50%'><IMG src='/aspnet_client/kkding/down.gif' align='middle' border='0'></TD>
                                    </TR>
                            </TABLE>
                        </TD>
                    </TR>
            </TABLE>
";
                result 
= String.Format(result,month.Text);
            }

            
catch
            
{
                
return "Month Control";
            }

            
return result;
        }

        
        
    }

}

你可能感兴趣的:(日历)