|
<DIV class=HtmlCode> 日历控件是.net自带的控件之一,功能强大,在很多项目开发中都有用到,对于blog系统来说更是必不可少。纵是好玉也仍需雕琢,为了使它更美观实用,我们还需要对它进行二次开发。 <BR> <BR> 新建一个用户控件,把calender控件拉进来。第一步是外观设置,这个根据你的需要,只需对它的相关属性做一些调整即可。下图是我调整后的界面 <BR> <IMG src="http://www.yesky.com/image20010518/267653.gif"> <BR> 属性设置如下: <BR> <BR> <asp:calendar id="Calendar1" CellPadding="2" Width="160px" TitleStyle-BackColor="#000000" <BR> BorderColor="#aaaaaa" <BR> DayHeaderStyle-BackColor="#5e715e" <BR> OtherMonthDayStyle-ForeColor="#cccccc" <BR> DayNameFormat="Full" <BR> runat="server" <BR> TitleStyle-ForeColor="#ffffff" <BR> NextPrevStyle-ForeColor="#ffffff" <BR> CellSpacing="1" <BR> WeekendDayStyle-BackColor="#eeeeee" <BR> DayHeaderStyle-ForeColor="#ffffff" <BR> SelectionMode="None" <BR> TodayDayStyle-BorderColor="#5e715e" <BR> TodayDayStyle-BorderWidth="1" <BR> TodayDayStyle-Font-Bold="true" <BR> TodayDayStyle-ForeColor="#5e715e" <BR> > <BR> <BR> 第二步是对内部功能的调整,这个工作主要集中在以下两个事件的处理上。 <BR> <BR> PreRender:当服务器控件将要呈现给其包含的Page对象时发生。 <BR> <BR> DayRender:当为Calendar控件在控件层次结构中创建每一天时发生。 <BR> <BR> 先定义三个整型变量和整型数组 <BR> <BR> private int[] arrCurrentDays,arrPreDays,arrNextDays; //三个变量分别是当前月,前一月,和下一个月 <BR> private int intCurrentMonth,intPreMonth,intNextMonth; //三个整型数组存放相对月份写有blog的日期 <BR> protected System.Web.UI.WebControls.Calendar Calendar1; //这个就是我们的日历控件了 <BR> <BR> 2. 下面我将分别给出这两个事件的源码,并在下面解释它实现的功能,如果你看不明白,可以先看下面的说明 <BR> <BR> PreRender <BR> <BR> private void Calendar1_PreRender(object sender, System.EventArgs e) <BR> { <BR> Thread threadCurrent = Thread.CurrentThread; <BR> CultureInfo ciNew = (CultureInfo)threadCurrent.CurrentCulture.Clone(); <BR> ciNew.DateTimeFormat.DayNames = new string[]{"日","一","二","三","四","五","六"}; <BR> ciNew.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday; <BR> threadCurrent.CurrentCulture = ciNew; <BR> } <BR> <BR> 以上代码改变了星期名称的显示。你只需改变字符数组的值就能改名称显示。 <BR> <BR> DayRender <BR> <BR> private void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e) <BR> { <BR> //该控件在创建每一天时发生。 <BR> <BR> CalendarDay d = ((DayRenderEventArgs)e).Day; <BR> TableCell c = ((DayRenderEventArgs)e).Cell; <BR> } <BR></DIV> |
|