Create a personal calendar control for your blog

zhaozj2021-02-16  54

The calendar control is one of the controls of the DOTNET, which is powerful, and it is useful in many project development, which is essential for the Blog system. It still needs to be carved in a good jade, in order to make it more beautiful and practical, we also need to develop it secondary.

The first step is to set up, this is required to make some adjustments to its related properties according to your needs. The picture below is the interface I adjusted.

The property is set as follows:

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, this work is mainly concentrated on the processing of the following two events.

Prerender: When the server control will be present to the PAGE object included.

Dayrender: When the Calendar control is created every day in the control hierarchy.

First define three integer variables and integer arrays

Private int [] ArrcurrentDays, Arrpredays, ArrnextDays; // The three variables are the current month, January, and the next month private int int, intnextMonth, IntnextMonth; // three integer array stores relative months written with blog Date Protected System.Web.ui.WebControls.calendar Calendar1; // This is our calendar control.

2. Below I will give the source code of these two events, and explain the features it implemented below. If you don't understand, you can first look at the following description.

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", " A "," two "," three "," four "," five "," six "}; cinew.datetimeformat.firstdayofweek = dayofweek.sunday; threadcurrent.currentculture = cinew;}

The above code changes the display of the weeks. You can change your name to display only if you want to change the value of the character array. Dayrender

Private void Calendar1_dayrender (object sender, system.web.ui.webcontrols.dayrenderEventArgs e) {// This control occurs every day. Calendarday D = ((DayRendeventargs) e) .day; TableCell C = ((DayRendreventArgs) e). Cell;

// Initialize the current month's date array if (INTPREMONTH == 0) {INTPREMONTH = D.date.month; // Note: The first month we get in the first month when the calendar control is initialized, but the former one intCurrentMonth month month = intPreMonth 1; if (intCurrentMonth> 12) intCurrentMonth = 1; intNextMonth = intCurrentMonth 1; if (intNextMonth> 12) intNextMonth = 1; arrPreDays = getArrayDay (d.Date.Year, intPreMonth); // Received the date array of blogs from the previous month ArrcurrentDays = GetArrayDay (D.date.Year, INTCURRENTMONTH); // Get date array of blogs in the month arrnextDays = GetArrayDay (D.date.Year, IntnexTmonth); // Get next month There is a date array of blog} int J = 0; if (d.date.month.equals (intPRemonth)) {while (! Arrpredays [j] .Equals (0)) {if (D.date.day.equals (arrpredays [j]) {c.controls.clear (); c.controls.add (new literalcontrol)

转载请注明原文地址:https://www.9cbs.com/read-21819.html

New Post(0)