先add添加进窗口,再设置样式
Vars("y") = Date.today().year
Vars("m") = Date.today().month
e.Form.Controls("月").text = Vars("y") & "年" & format(Vars("m"),"00") & "月"
Dim a As Date = "#" & Vars("m") & "/1/" & Vars("y") & "#"
Dim lb As WinForm.label
Dim Month As String = "|正|二|三|四|五|六|七|八|九|十|冬|腊"
Dim Months() As String
Months = Month.split("|")
Dim Multi As String = "|初一|初二|初三|初四|初五|初六|初七|初八|初九|初十|十一|十二|十三|十四|"
Multi = Multi & "十五|十六|十七|十八|十九|廿十|廿一|廿二|廿三|廿四|廿五|廿六|廿七|廿八|廿九|卅十"
Dim Values() As String
Values = Multi.split("|")
For i As Integer = 1 To Date.DaysInMonth(Vars("y"),Vars("m"))
lb = e.Form.CreateControl(i & "日", ControlTypeEnum.label)
e.Form.Controls("Panel1").AddControl(lb)
lb.Left =60*((i-1+a.DayOfWeek) Mod 7)
lb.Top = 47*((i-1+a.DayOfWeek)\7)
lb.Width =65
lb.Height =35
Dim nl As New Lunar("#" & Vars("m") & "/" & i & "/" & Vars("y") & "#")
If nl.day = 1
'lb.BackColor = Color.Red
If nl.LeapMonth = Nothing OrElse nl.Month < nl.LeapMonth Then
lb.text = i & chr(10) & Months(nl.month) & "月"
End If
If nl.LeapMonth = nl.Month Then
lb.text = i & chr(10) & "闰" & Months(nl.month-1) & "月"
End If
If nl.LeapMonth > 0 Then
If nl.Month > nl.LeapMonth Then
lb.text = i & chr(10) & Months(nl.month-1) & "月"
End If
End If
Else
lb.text = i & chr(10) & Values(nl.Day)
lb.BackColor = Color.PaleTurquoise
End If
If ((i-1+a.DayOfWeek) Mod 7) = 0 OrElse ((i-1+a.DayOfWeek) Mod 7) = 6
lb.ForeColor = Color.Red
End If
Dim n2 As New Lunar("#" & Vars("m") & "/" & i & "/" & Vars("y") & "#")
If n2.SolarDate = Date.Today()
lb.BackColor = Color.DarkTurquoise
End If
lb.BorderStyle = System.Windows.Forms.BorderStyle.none
lb.TextAlign=System.Windows.Forms.HorizontalAlignment.Center
lb.TopMost=True
lb.Cursor = Windows.Forms.Cursors.Hand
Next