Forms 在文本框powershell窗体中显示日期

Forms 在文本框powershell窗体中显示日期,forms,powershell,Forms,Powershell,我正在编写一个脚本,从用户输入中获取数据作为日期,当我选择另一个日期时,它不会显示在文本框中,请建议问题出在哪里 [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $Form = New-Object System.Windows.For

我正在编写一个脚本,从用户输入中获取数据作为日期,当我选择另一个日期时,它不会显示在文本框中,请建议问题出在哪里

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$Form = New-Object System.Windows.Forms.Form    
$Form.Size = New-Object System.Drawing.Size(800,600)
$Form.Text = "test"
$Form.FormBorderStyle = "FixedDialog"

$TextBoxlabel = New-Object System.Windows.Forms.Label
$TextBoxlabel.Location = New-Object System.Drawing.Point(10,50)
$TextBoxlabel.Size = New-Object System.Drawing.Size(100,20)
$TextBoxlabel.Text = 'Input No:'
$form.Controls.Add($TextBoxlabel)

$TextBox = New-Object System.Windows.Forms.TextBox 
$TextBox.Location = New-Object System.Drawing.Size(120,50) 
$TextBox.Size = New-Object System.Drawing.Size(180,20) 
$TextBox.MultiLine = $false
$TextBox.ScrollBars = "Vertical" 
$Form.Controls.Add($TextBox)

$StartDatelabel = New-Object System.Windows.Forms.Label
$StartDatelabel.Location = New-Object System.Drawing.Point(10,100)
$StartDatelabel.Size = New-Object System.Drawing.Size(100,20)
$StartDatelabel.Text = 'Start Date:'
$form.Controls.Add($StartDatelabel)

$StartDateTextBox = New-Object System.Windows.Forms.TextBox 
$StartDateTextBox.Location = New-Object System.Drawing.Size(120,100) 
$StartDateTextBox.Size = New-Object System.Drawing.Size(100,20) 
$StartDateTextBox.MultiLine = $false
$StartDateTextBox.ScrollBars = "Vertical"
$Form.Controls.Add($StartDateTextBox)

$Button1 = New-Object System.Windows.Forms.Button 
$Button1.Location = New-Object System.Drawing.Size(220,100) 
$Button1.Size = New-Object System.Drawing.Size(50,20) 
$Button1.Text = "Date1"

$Button1.Add_Click({

$StartDateInput = New-Object System.Windows.Forms.MonthCalendar
$StartDateInput.ShowTodayCircle = $false
$StartDateInput.MaxSelectionCount = 1
$StartDateInput.Location = New-Object System.Drawing.Size(120,120)
$StartDateTextBox.Text = $StartDateInput.SelectionStart
$form.Controls.Add($StartDateInput)
})

$Form.Controls.Add($Button1)
$OutputTextBox = New-Object System.Windows.Forms.TextBox 
$OutputTextBox.Location = New-Object System.Drawing.Size(10,320) 
$OutputTextBox.Size = New-Object System.Drawing.Size(760,200) 
$OutputTextBox.MultiLine = $true
$OutputTextBox.ScrollBars = "Vertical"
$OutputTextBox.ReadOnly = $true
$Form.Controls.Add($OutputTextBox)

$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()

当我选择日期(默认日期除外)时,它不会显示在文本框中

你说的“选择日期”是什么意思?当我选择其他日期时,例如:5月9日,它应该在textboxOh中打印值,如果您的意思是在MonthCalendar控件上选择日期,那么听起来您需要为该控件注册一个事件处理程序,该事件处理程序将在选择日期时设置文本框的值。