在日历中更改当前星期的背景颜色 [英] Change background color of current week in calendar
本文介绍了在日历中更改当前星期的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在日历控件中更改所选日期的当前星期的底色.
I want change the back color of the current week on the selected date in a calendar control.
推荐答案
^ ],然后展开标有日历主题的项目.
Go here [^], and expand the item labeled Calendar Theming.
好吧,这就是它的工作方式.您有一个日历"控件,并且希望当前星期的选定日期"颜色有所不同.
首先,您必须找出startOfWeek
和endOfWeek
每当选定的日期范围"事件出现在开始"和结束"范围之间时,您必须更改SelectedDayStyle
,否则将使用默认样式进行重置.
Well, this is how it will work. You have a Calendar Control, and you want the current week Selected Date Color something different.
First of all, you have to find outstartOfWeek
andendOfWeek
When ever the Selected Date Range event coming in between the Start and End of week range, you have to change theSelectedDayStyle
, else reset with default style.
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
if (Calendar1.SelectedDate.Date >= startOfWeek.Date && Calendar1.SelectedDate.Date <= endOfWeek.Date)
{
Calendar1.SelectedDayStyle.BackColor = System.Drawing.Color.LightGreen;
}
else
{
Calendar1.SelectedDayStyle.BackColor = System.Drawing.Color.Gray;
}
}
这就是您想要的. :thumbsup:
现在,如何计算我留在您身上的星期开始日期(startOfWeek
)和星期结束日期(endOfWeek
);)
This is what you were looking for. :thumbsup:
Now, How to calculate the week Start Date (startOfWeek
) and Week End Date (endOfWeek
) I left on you ;)
我找到解决方案对于从星期六到星期五,但是有可能在Java脚本中进行同样的思考
I find solution For select Working Week from Saturday to Friday but it is possible do same think in java script
public void selectWorkingWeek(DateTime CurrentDate)
{
DateTime SelectedDate = Calendar1.SelectedDate;
int Positionday = ReturndayPosition(CurrentDate.DayOfWeek.ToString());
for (int i = Positionday; i > 0; i--)
{
DateTime DT = new DateTime();
DT = SelectedDate;
DT= DT.AddDays(-i);
Calendar1.SelectedDates.Add(DT);
}
for (int j = 1; j <= 6-Positionday; j++)
{
DateTime DT = new DateTime();
DT = SelectedDate;
DT = DT.AddDays(j);
Calendar1.SelectedDates.Add(DT);
}
}
public int ReturndayPosition(string day)
{
int dayPosition = 0;
switch (day.ToUpper())
{
case "SATURDAY": dayPosition = 0; break;
case "SUNDAY": dayPosition = 1; break;
case "MONDAY": dayPosition = 2; break;
case "TUESDAY": dayPosition = 3; break;
case "WEDNESDAY": dayPosition = 4; break;
case "THURSDAY": dayPosition = 5; break;
case "FRIDAY": dayPosition = 6; break;
}
return dayPosition;
}
感谢您的帮助.
Thanks for help.
这篇关于在日历中更改当前星期的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文