Calendar controls are one of the. NET controls that are powerful and useful in many project development, and are essential for blogging systems. The good jade also needs to carve, in order to make it more beautiful and practical, we also need to develop it two times.
Create a new user control and pull the calender control in. The first step is the appearance setting, which, depending on your needs, can only be adjusted for its related properties. The following figure is my adjusted interface
The properties are set as follows:
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 function, which focuses on the following two events.
PreRender: Occurs when a server control is to be rendered to its contained page object.
DayRender: Occurs when you create each day for a calendar control in the control hierarchy.
Define three integer variables and integer arrays first
Private int[] arrcurrentdays,arrpredays,arrnextdays; Three variables are the current month, the previous January, and the next one months private int intcurrentmonth,intpremonth,intnextmonth; Three integer arrays hold relative month date of blog protected System.Web.UI.WebControls.Calendar Calendar1; And this is our Calendar control. |
2. Below I will give the source of these two events, and explain its implementation below, if you do not understand, you can first look at the following instructions
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[]{"Day", "one", "two", "three", "four", "five", "six"}; CiNew.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday; Threadcurrent.currentculture = cinew; } |
The above code changes the display of the week name. You can change the name display simply by changing the value of the character array.
DayRender
private void Calendar1_dayrender (object sender, System.Web.UI.WebControls.DayRenderEventArgs e) { The control occurs each day when it is created.
CalendarDay d = ((Dayrendereventargs) e). Day; TableCell c = ((Dayrendereventargs) e). Cell; } |