.NET DateTimePicker 日历未出现在 PowerShell 表单中
.NET DateTimePicker calendar not appearing in PowerShell form
我试图在 PowerShell 的 WinForms 表单中显示 DateTimePicker。出现表单时,可以更改日期,但点击下拉按钮不会显示日历。好像有什么事情发生了,只是看不见而已。
我在这里错过了什么愚蠢的东西?
$form = New-Object Windows.Forms.Form
$form.Size = New-Object Drawing.Size @(400, 400)
$form.StartPosition = "CenterScreen"
$form.Text = "When do you want the snapshot to be taken?"
$form.Font = New-Object Drawing.Font("Microsoft Sans Serif",12)
$form.FormBorderStyle = [Windows.Forms.FormBorderStyle]::Fixed3D
$panel = New-Object Windows.Forms.FlowLayoutPanel
$panel.Height = 400
$panel.Width = 400
$panel.AutoScroll = $true
$panel.FlowDirection = [Windows.Forms.FlowDirection]::TopDown
$panel.WrapContents = $false
$titleText = New-Object Windows.Forms.Label
$titleText.AutoSize = $true
$titleText.Text = "When do you want the snapshot to be taken?"
$panel.Controls.Add($titleText)
$datePicker = New-Object Windows.Forms.DateTimePicker
$datePicker.ShowUpDown = $false
$datePicker.MinDate = $now
$datePicker.MaxDate = $now.AddMonths(3); #arbitrary
$datePicker.MaxSelectionCount = 1
$datePicker.Width = 350
$datePicker.Enabled = $false
$panel.Controls.Add($datePicker)
$form.Controls.Add($panel)
$drc = $form.ShowDialog()
你的代码似乎在我的电脑上运行良好。我复制粘贴了您的代码并将 Add-Type 添加到顶部:
Add-Type -AssemblyName System.Windows.Forms
并更改了 $datePicker.Enabled:
$datePicker.Enabled = $true
当 运行 时,我可以更改 date/time 并且下拉列表也按预期工作:
我试图在 PowerShell 的 WinForms 表单中显示 DateTimePicker。出现表单时,可以更改日期,但点击下拉按钮不会显示日历。好像有什么事情发生了,只是看不见而已。
我在这里错过了什么愚蠢的东西?
$form = New-Object Windows.Forms.Form
$form.Size = New-Object Drawing.Size @(400, 400)
$form.StartPosition = "CenterScreen"
$form.Text = "When do you want the snapshot to be taken?"
$form.Font = New-Object Drawing.Font("Microsoft Sans Serif",12)
$form.FormBorderStyle = [Windows.Forms.FormBorderStyle]::Fixed3D
$panel = New-Object Windows.Forms.FlowLayoutPanel
$panel.Height = 400
$panel.Width = 400
$panel.AutoScroll = $true
$panel.FlowDirection = [Windows.Forms.FlowDirection]::TopDown
$panel.WrapContents = $false
$titleText = New-Object Windows.Forms.Label
$titleText.AutoSize = $true
$titleText.Text = "When do you want the snapshot to be taken?"
$panel.Controls.Add($titleText)
$datePicker = New-Object Windows.Forms.DateTimePicker
$datePicker.ShowUpDown = $false
$datePicker.MinDate = $now
$datePicker.MaxDate = $now.AddMonths(3); #arbitrary
$datePicker.MaxSelectionCount = 1
$datePicker.Width = 350
$datePicker.Enabled = $false
$panel.Controls.Add($datePicker)
$form.Controls.Add($panel)
$drc = $form.ShowDialog()
你的代码似乎在我的电脑上运行良好。我复制粘贴了您的代码并将 Add-Type 添加到顶部:
Add-Type -AssemblyName System.Windows.Forms
并更改了 $datePicker.Enabled:
$datePicker.Enabled = $true
当 运行 时,我可以更改 date/time 并且下拉列表也按预期工作: