The calendar control is one of the controls that comes with .net. It has powerful functions and is used in many project developments. It is even more essential for blog systems. Even good jade still needs to be carved. In order to make it more beautiful and practical, we also need to carry out secondary development on it.
Create a new user control and pull in the calendar control. The first step is to set the appearance. Based on your needs, you only need to make some adjustments to its related properties. The picture below is my adjusted interface
The property settings are as follows:
<asp:calendar id="Calendar1" CellPadding="2" Width="160px" TitleStyle-BackColor="#000000" BorderColor="#aaaaaa" DayHeaderStyle-BackColor="#5e715e" OtherMonthDayStyle-ForeColor="#cccccc" DayNameFormat="Full" runat="server" TitleStyle-ForeColor="#ffffff" NextPrevStyle-ForeColor="#ffffff" CellSpacing="1" WeekendDayStyle-BackColor="#eeeeee" DayHeaderStyle-ForeColor="#ffffff" SelectionMode="None" TodayDayStyle-BorderColor="#5e715e" TodayDayStyle-BorderWidth="1" TodayDayStyle-Font-Bold="true" TodayDayStyle-ForeColor="#5e715e" >
The second step is to adjust the internal functions. This work mainly focuses on the following two events. of processing.
PreRender: Occurs when the server control is about to be rendered to its containing Page object.
DayRender: Occurs when each day is created for the Calendar control in the control hierarchy.
First define three integer variables and integer array
private int[] arrCurrentDays,arrPreDays,arrNextDays; //三个变量分别是当前月,前一月,和下一个月 private int intCurrentMonth,intPreMonth,intNextMonth; //三个整型数组存放相对月份写有blog的日期 protected System.Web.UI.WebControls.Calendar Calendar1; //这个就是我们的日历控件了
2. Below I will give the source code of these two events respectively, and in The functions it implements are explained below. If you don’t understand, you can read the following instructions first
PreRender
private void Calendar1_PreRender(object sender, System.EventArgs e) { Thread threadCurrent = Thread.CurrentThread; CultureInfo ciNew = (CultureInfo)threadCurrent.CurrentCulture.Clone(); ciNew.DateTimeFormat.DayNames = new string[]{"日","一","二","三","四","五","六"}; ciNew.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday; threadCurrent.CurrentCulture = ciNew; }
The above code changes the display of week names. You only need to change the value of the character array to change the name display.
DayRender
private void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e) { //该控件在创建每一天时发生。 CalendarDay d = ((DayRenderEventArgs)e).Day; TableCell c = ((DayRenderEventArgs)e).Cell; }
The above is the detailed content of Detailed explanation of the tutorial on implementing a calendar on Blog. For more information, please follow other related articles on the PHP Chinese website!