本文介绍了是否可以创建一个日历,其中每周从周一而不是周日开始?怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮帮我,我正在创建一个自定义日历,但我想在星期一开始这一周,



这里是代码 -

Please help me out I'm creating a customized calendar but I want to start the week with Monday,

here is the code--

Public Sub DrawCalendar()
     IsInitializing = True

     Dim intNumberOfDays As Integer
     Dim datFirstDay As Date

     Dim x As Integer
     Dim i As Integer
     'Clean the txtDay / lblDay
     For i = 0 To 41
         lblDay(i).Text = ""
         lblDay(i).BackColor = Color.FromKnownColor(KnownColor.Control)
         lblDay(i).ForeColor = Color.FromKnownColor(KnownColor.ControlText)
         txtDay(i).BackColor = Color.FromKnownColor(KnownColor.Window)
         txtDay(i).ForeColor = Color.FromKnownColor(KnownColor.ControlText)
         picDay(i).BackgroundImage = Nothing
         txtDay(i).Text = ""
         picDay(i).Visible = True
     Next i

     HeaderLable.Text = _SelectedDate.ToString("MMMM yyyy")
     MonthCombo.SelectedIndex = _SelectedDate.Month - 1
     YearUpDown.Value = _SelectedDate.Year

     intNumberOfDays = _SelectedDate.DaysInMonth(_SelectedDate.Year, _SelectedDate.Month)
     datFirstDay = CDate(_SelectedDate.Month & "/" & 1 & "/" & _SelectedDate.Year)
     x = 1

     'Gets an array list of days

     Dim trgDate As Date

     Dim dv As DataView = Nothing
     If Not DataSource Is Nothing Then
         If TableName.Length > 0 Then
             If DateMember.Length > 0 Then
                 If TimeMember.Length > 0 Then
                     Try
                         dv = DataSource.DefaultViewManager.CreateDataView(DataSource.Tables(TableName))
                     Catch ex As Exception
                         MessageBox.Show(ex.Message)
                     End Try
                 End If
             End If
         End If
     End If

     For i = Weekday(datFirstDay) - 1 To intNumberOfDays + Weekday(datFirstDay) - 2
         lblDay(i).Text = CStr(x)

         ' Today gets special background
         If _SelectedDate.Month = Now.Month And _SelectedDate.Year = Now.Year Then
             If x = Now.Day Then
                 txtDay(i).BackColor = System.Drawing.Color.LightGreen
                 lblDay(i).BackColor = System.Drawing.Color.Green
             End If
         End If

         ' show appontments
         SetAppointment(dv, New DateTime(_SelectedDate.Year, _SelectedDate.Month, x), i, False)

         x = x + 1
     Next

     'Make the picDays that aren't from the month invisible
     x = 1
     For i = 27 To 41
         If lblDay(i).Text = "" Then
             lblDay(i).Text = Str(x)
             lblDay(i).ForeColor = Color.FromKnownColor(KnownColor.ControlDark)
             SetAppointment(dv, New DateTime(_SelectedDate.AddMonths(1).Year, _SelectedDate.AddMonths(1).Month, x), i, True)
             x += 1
             txtDay(i).BackColor = Color.FromKnownColor(KnownColor.Control)
             txtDay(i).ForeColor = Color.FromKnownColor(KnownColor.ControlDark)
         End If
     Next

     x = DateTime.DaysInMonth(_SelectedDate.AddMonths(-1).Year, _SelectedDate.AddMonths(-1).Month)
     For i = 7 To 0 Step -1
         If lblDay(i).Text = "" Then
             lblDay(i).Text = Str(x)
             lblDay(i).ForeColor = Color.FromKnownColor(KnownColor.ControlDark)
             SetAppointment(dv, New DateTime(_SelectedDate.AddMonths(-1).Year, _SelectedDate.AddMonths(-1).Month, x), i, True)
             x -= 1
             txtDay(i).BackColor = Color.FromKnownColor(KnownColor.Control)
             txtDay(i).ForeColor = Color.FromKnownColor(KnownColor.ControlDark)
         End If
     Next

     IsInitializing = False
 End Sub

推荐答案


这篇关于是否可以创建一个日历,其中每周从周一而不是周日开始?怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 03:12