首页 > 解决方案 > Winform.MonthCalendar.Size 在 .CalendarDimensions 更新后未更新

问题描述

我有一个简单的 WinForm,它只包含一个WinForm.MonthCalendar控件。

考虑以下:

Sub New(Optional Title As String = Nothing, Optional DisplayMonths As Integer? = Nothing)

    If Title Is Nothing Then Title = "Pick a date"
    If DisplayMonths Is Nothing Then DisplayMonths = 1

    InitializeComponent()
    AdjustMonths(DisplayMonths.Value)
    Me.Text = Title

End Sub

Private Sub AdjustMonths(Count As Integer)

    Dim CalendarDim As Drawing.Size = New Drawing.Size(1, 1)
    Select Case Count
        Case 1
            'Do nothing
        Case 2
            CalendarDim.Height *= 2
        Case 3
            CalendarDim.Height *= 3
        Case 4
            CalendarDim.Height *= 2
            CalendarDim.Width *= 2
        Case 6
            CalendarDim.Width *= 2
            CalendarDim.Height *= 3
        Case 9
            CalendarDim.Height *= 3
            CalendarDim.Width *= 3
        Case 12
            CalendarDim.Height *= 3
            CalendarDim.Width *= 4
        Case Else
            Throw New ArgumentException("Supported values are 1, 2, 3, 4, 6, 9, and 12.", NameOf(Count))
    End Select
    Me.MonthsDisplayed = Count

    Me.MonthCalendar.CalendarDimensions = CalendarDim
    'Me.Show()
    'Me.Hide()
    Me.ClientSize = Me.MonthCalendar.Size

End Sub

随后显示 winform 时,除非我取消注释该 hack,否则它的大小不正确Me.Show;Me.Hide,由于显而易见的原因,这远非理想。我认为这是因为Me.MonthCalendar.Size除非显示/绘制,否则不会返回正确的尺寸。知道如何获得正确的值吗?

我试过Me.PerformLayout, Me.Refresh, Me.Update, 但没有用。

标签: .netwinformsmonthcalendar

解决方案


推荐阅读