.net - 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
, 但没有用。
解决方案
推荐阅读
- c# - C#soap 客户端错误“请求失败,HTTP 状态 404:未找到。”
- android - Material Design TextInputLayout PasswordToggle Position
- c - 我们可以声明数组的大小为零吗?
- pandas - 如何在 Pandas 中将所有 IP 地址列表转换为十进制数字
- python - 熊猫应用将列表返回到更多列的函数
- c# - c# 使用映射将不同的可能 Json 反序列化为一个唯一对象
- python - df to datetime 对象中的 YYMM 整数
- react-native - 如何使用内置缓存在 AppSyncClient 中保留“默认”本地状态
- docker - 如何重新启动使用 exitCode 127 过早退出的 docker 容器?
- javascript - 如何获取 CSS 样式的类