如何在Calendar控件中突出显示其他日期? [英] How do I highlight alternate days in Calendar control?

查看:96
本文介绍了如何在Calendar控件中突出显示其他日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我的代码每周四都会突出显示,但是,我希望它突出其他每一个星期天。



Right now my code highlights every thursday, however, I want it to highlight every other thurdsay.

'Pay Day's Every other Thursday
        If e.Day.[Date].DayOfWeek.ToString() = "Thursday" Then
            e.Cell.BackColor = Color.Lime
        End If










Protected Sub cal_DayRender(sender As Object, e As DayRenderEventArgs)

'Pay Day's Every other Thursday
        If e.Day.[Date].DayOfWeek.ToString() = "Thursday" Then
            e.Cell.BackColor = Color.Lime
        End If

end sub

推荐答案

搞定了!



我选了一个我知道的历史日期是星期四 - 例如1965年9月30日(这是Thunderbirds首次在英国电视台播出时 - 我知道,我很伤心)



计算从该日期到日期的天数问题 - 如果你用14修改那个数字(因为你想要它的星期四它必须是2 * 7),你将得到0或7.所以只是当它为零时的颜色。



喜欢这个
Got it!

I picked out a historical date that I knew was a Thursday - e.g. 30th September 1965 (which is when Thunderbirds was first broadcast on UK television - I know, I'm sad)

Calculate the number of days from that date to the date in question - if you mod that number with 14 (because you want alternate thursdays it has to be 2 * 7), you will either get 0 or 7. So just color in the day when it's zero.

Like this
Private Sub cal_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
    'Pay Day's Every other Thursday
    If e.Day.[Date].DayOfWeek.ToString() = "Thursday" Then        
        If DateDiff(DateInterval.Day, DateSerial(1965, 9, 30), e.Day.[Date]) Mod 14 = 0 Then
            e.Cell.BackColor = Color.Lime
        End If
    End IfEnd Sub



我很喜欢 - 谢谢!




I enjoyed that - thank you!


这篇关于如何在Calendar控件中突出显示其他日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆