代码之家  ›  专栏  ›  技术社区  ›  Sinister Swan

Monthview粗体显示每个值

  •  0
  • Sinister Swan  · 技术社区  · 11 年前

    我在表单中创建了一个Monthview和TimePicker。我希望用户选择时间,并选择一个月份,该月份将加粗每次选择的值,然后选择“确定”将插入值。我觉得这一切都很好。问题是,如果用户选择一个日期,然后选择另一个日期或其他日期,则所有日期都将变为粗体。我希望BOLD只关注最近的每一次点击。。如果这有意义,那么用户就知道他选择了什么价值。

    这是我的点击代码:

      Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
    
     Dim x As Date
    
        x = MonthView1.value
        MonthView1.DayBold(x) = True ' Bold the date
    
    End Sub
    

    我需要什么方法?是否有某种最近点击的属性?

    2 回复  |  直到 7 年前
        1
  •  1
  •   Zeno    11 年前

    请尝试以下代码:

    Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
    
    Dim x As Date
    Dim MaxDate As Date
    Dim MinDate As Date
    
    MinDate = DateSerial(Year(DateClicked), Month(DateClicked), 1) 'Get first date of current month based on clicked date
    MaxDate = DateSerial(Year(DateClicked), Month(DateClicked) + 1, 0) 'Get last date of current month based on clicked date
    
    x = ActiveCell.Value 'Retreive value of last Bold date
    If x >= MinDate And x <= MaxDate Then 'If last Bold date is in the current month then unbold it
        MonthView1.DayBold(x) = False
    End If
    
    MonthView1.DayBold(DateClicked) = True 'Bold the clicked date
    ActiveCell.Value = DateClicked 'Store current date in a sheet
    
    End Sub
    

    其想法是将粗体日期保存在工作表中(如果需要,可以隐藏它),并在选择其他日期时检索它。粗体格式将从上一日期中删除,并应用于当前日期。

        2
  •  -1
  •   Cindy Meister    9 年前

    关于MonthView中的粗体

    '<code>
    Private Sub CommandButton1_Click()
      Dim Ss(50) As Boolean
    
      'put  in module  DaysToBold$  and DatesToBold$  as public variables
      DaysToBold = "713"  ' sat Sun Tue
      ' DaysToBold = "" ' for none
      DatesToBold = "x,1,2,12,22,30"
     ' DatesToBold = "x" ' if none
    
      MonthView21_GetDayBold Now, 49, Ss
    
    End Sub
    
    Private Sub MonthView21_GetDayBold(ByVal StartDate As Date, _
                ByVal Count As Integer, State() As Boolean)
      Dim I As Integer, Mi%, DTB, DI%, DAd%
      On Error Resume Next ' seem to be  negative indices into State() even if declared  ( -10 to 50)
    
      For Mi = 1 To Len(DaysToBold)  ' mark of the Days of week to bold
        I = Mid(DaysToBold, Mi, 1)  ' single digits 1 ..7  excel translate to integer
        While I < Count
            State(I - MonthView21.StartOfWeek) = True
            I = I + 7  ' down the column
        Wend
      Next Mi
    
    
      DTB = Split(DatesToBold, ",")
      If UBound(DTB) > 0 Then
        With MonthView21
            For I = 1 To UBound(DTB)  ' mark the date numbers to bold
              DI = Weekday(DateSerial(Year(.Value), Month(.Value), 1), .StartOfWeek)
             If DI = 1 Then DAd = 5 Else DAd = -2  ' 7 days of last month there if Di=1
                State(DTB(I) + DI + DAd) = True
            Next I
        End With
      End If
    End Sub
    '</code>