选择日期范围日历Powershell

时间:2019-02-13 17:29:05

标签: powershell

我希望能够在日历中选择日期范围(并突出显示所选内容)

到目前为止,我在SelectionRange中只获得1个日期,而不是整个选择数组。我不知道为什么

Function Pick-Date {
  $Cal = New-Object System.Windows.Forms.MonthCalendar
  $Cal.ShowWeekNumbers = $true
  $Cal.MaxSelectionCount = 365
  $Cal.Dock = 'Fill'
  $Form = New-Object Windows.Forms.Form
  $Form.text = "Colocar fecha que desea enviar. Y presiona Enter"
  $Form.Size = New-Object Drawing.Size @(800,600)
  $btnSelect = New-Object System.Windows.Forms.Button
  $btnSelect.Size = "80,80"
  $Dates = $Cal.SelectionRange
  $btnSelect.add_Click( { busca_tiquete ($Dates)} )
  #$btnSelect.add_Click( { busca_tiquete (Get-Date($Cal.SelectionStart))} )
  $btnSelect.Location = New-Object System.Drawing.Point(230,480)
  $btnSelect.Text="ENTER"
  $CancelButton = New-Object System.Windows.Forms.Button
  $CancelButton.Location = New-Object System.Drawing.Point(330,480)
  $CancelButton.Size = "80,80"
  $CancelButton.Text = 'Cancel'
  $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
  $Form.CancelButton = $CancelButton
  $Form.Controls.Add($CancelButton)
  $Form.Controls.Add($btnSelect )
  $Form.AcceptButton = $btnSelect
  $Form.Controls.Add($Cal)
  $Form.Add_Shown({$Form.Activate()})
  [void]$Form.ShowDialog()
  #return (Get-Date($Cal.SelectionStart))
}

感谢您的帮助。

提前致谢!

1 个答案:

答案 0 :(得分:1)

目前尚不清楚您的busca_tiquete ($Dates)的功能,但是它在函数中的位置错误。 在命令$cal.SelectionRange

之后填充[void]$Form.ShowDialog()

所以这可能会做到:

Function Pick-Date {
    $Cal = New-Object System.Windows.Forms.MonthCalendar
    $Cal.ShowWeekNumbers = $true
    $Cal.MaxSelectionCount = 365
    $Cal.Dock = 'Fill'
    $Form = New-Object Windows.Forms.Form
    $Form.text = "Colocar fecha que desea enviar. Y presiona Enter"
    $Form.Size = New-Object Drawing.Size @(800,600)
    $btnSelect = New-Object System.Windows.Forms.Button
    $btnSelect.Size = "80,80"
    $btnSelect.Location = New-Object System.Drawing.Point(230,480)
    $btnSelect.Text="ENTER"
    $CancelButton = New-Object System.Windows.Forms.Button
    $CancelButton.Location = New-Object System.Drawing.Point(330,480)
    $CancelButton.Size = "80,80"
    $CancelButton.Text = 'Cancel'
    $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
    $Form.CancelButton = $CancelButton
    $Form.Controls.Add($CancelButton)
    $Form.Controls.Add($btnSelect )
    $Form.AcceptButton = $btnSelect
    $Form.Controls.Add($Cal)
    $Form.Add_Shown({$Form.Activate()})
    [void]$Form.ShowDialog()
    ## $$Dates will have start and end property of [datetime] type.
    $Dates = $Cal.SelectionRange
    ## unclear what the next command does/returns
    busca_tiquete $Dates
}
相关问题