当前位置:编程学习 > C#/ASP.NET >>

想用vb.net编写一个万年历软件,求教!

请问这个需要用什么控件呢?万年历,农历和节气什么的如何添加呢?哪位大哥能指点一二,小弟不胜感激! --------------------编程问答-------------------- 用一个什么都有的控件那你就不需要编写什么了,如果想自己做就查询好各种数据之间的关系,用数学算,然后用一些基本控件就可以了. --------------------编程问答-------------------- 哦!没接触过这么复杂的编程,能举个例子吗?比如界面都需要用什么控件做呢? --------------------编程问答-------------------- 这个需要算法的。万年历是先得到每一年的大小月的数据然后计算天数再计算到每一天的具体日期。
节气的日期好像可以算出来。
具体如下:
'下面是一个关于VB的农历算法
  
  '日期数据定义方法如下
  
  '前12个字节代表1-12月为大月或是小月,1为大月30天,0为小月29天,
  
  '第13位为闰月的情况,1为大月30天,0为小月29天,第14位为闰月的月
  
  '份,如果不是闰月为0,否则给出月份,10、11、12分别用A、B、C来表
  
  '示,即使用16进制。最后4位为当年家农历新年-即农历1月1日所在公历
  
  '的日期,如0131代表1月31日。
  
  'GetYLDate函数使用方式如下tYear为要输入的年,tMonth为月,tDay为
  
  '日期,YLyear是返回值,返加农历的年份,如甲子年,YLShuXing返回
  
  '的是属象,如鼠。IsGetGl是设置是不是通过农历取公历值,如果是,
  
  '前三个返回相应的公历日期,而且返回值是一个公历日期。
   --------------------编程问答-------------------- '下面是一个关于VB的农历算法
  
  '日期数据定义方法如下
  
  '前12个字节代表1-12月为大月或是小月,1为大月30天,0为小月29天,
  
  '第13位为闰月的情况,1为大月30天,0为小月29天,第14位为闰月的月
  
  '份,如果不是闰月为0,否则给出月份,10、11、12分别用A、B、C来表
  
  '示,即使用16进制。最后4位为当年家农历新年-即农历1月1日所在公历
  
  '的日期,如0131代表1月31日。
  
  'GetYLDate函数使用方式如下tYear为要输入的年,tMonth为月,tDay为
  
  '日期,YLyear是返回值,返加农历的年份,如甲子年,YLShuXing返回
  
  '的是属象,如鼠。IsGetGl是设置是不是通过农历取公历值,如果是,
  
  '前三个返回相应的公历日期,而且返回值是一个公历日期。
   --------------------编程问答-------------------- 多谢楼上,我再研究研究,有不懂的地方,再来请教! --------------------编程问答-------------------- 关键是农历

#Region " 返回农历 "
    '返回农历
    'cCalendar.MaxSupportedDateTime  返回支持的最大日期,即2101-1-28
    'cCalendar.MinSupportedDateTime  返回支持的最小日期,即190-2-19
    Private cCalendar As New System.Globalization.ChineseLunisolarCalendar
    Public Function PubFunGet_CNDate(ByVal sDateTime As Date) As String
        cCalendar = New System.Globalization.ChineseLunisolarCalendar
        Dim lyear As Integer = cCalendar.GetYear(sDateTime)
        Dim lmonth As Integer = cCalendar.GetMonth(sDateTime)
        Dim lday As Integer = cCalendar.GetDayOfMonth(sDateTime)
        Dim lweek As Integer = cCalendar.GetDayOfWeek(sDateTime)

        '获取闰月, 0 则表示没有闰月
        Dim leapMonth As Integer = cCalendar.GetLeapMonth(lyear)
        Dim isleap As Boolean = False

        If (leapMonth > 0) Then
            If (leapMonth = lmonth) Then
                '闰月
                isleap = True
                lmonth = lmonth - 1
            ElseIf (lmonth > leapMonth) Then
                lmonth = lmonth - 1
            End If
        End If

        Return String.Concat(GetLunisolarYear(lyear), IIf(isleap = True, "闰年", "年"), GetLunisolarMonth(lmonth), "月", GetLunisolarDay(lday))
    End Function

    '十天干
    Private tiangan As String() = {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"}
    '十二地支
    Private dizhi As String() = {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"}
    '十二生肖
    Private shengxiao As String() = {"鼠", "牛", "虎", "免", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"}
    '农历月
    Private months As String() = {"正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二(腊)"}
    '农历日
    Private days1 As String() = {"初", "十", "廿", "三"}
    Private days As String() = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十"}
    '返回农历年(天干 地支 生肖)
    Private Function GetLunisolarYear(ByVal year As Integer) As String
        GetLunisolarYear = ""
        If (year > 3) Then
            Dim tgIndex As Integer = (year - 4) Mod 10
            Dim dzIndex As Integer = (year - 4) Mod 12
            Return tiangan(tgIndex) & dizhi(dzIndex) & "[" & shengxiao(dzIndex) & "]"
        End If
        '无效的年份!
    End Function

    '返回生肖
    Private Function GetShengXiao(ByVal sDateTime As Date) As String
        Return shengxiao(cCalendar.GetTerrestrialBranch(cCalendar.GetSexagenaryYear(sDateTime)) - 1)
    End Function

    '返回农历月
    Private Function GetLunisolarMonth(ByVal month As Integer) As String
        GetLunisolarMonth = ""
        If (month < 13 AndAlso month > 0) Then
            Return months(month - 1)
        End If
        '无效的月份!
    End Function

    '返回农历日
    Private Function GetLunisolarDay(ByVal day As Integer) As String
        GetLunisolarDay = ""
        If (day > 0 AndAlso day < 32) Then
            If (day <> 20 AndAlso day <> 30) Then
                Return String.Concat(days1((day - 1) \ 10), days((day - 1) Mod 10))
            Else
                Return String.Concat(days((day - 1) \ 10), days1(1))
            End If
        End If
        '无效的日!
    End Function
#End Region
补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,