Powershell:MaskedTextBox 获取文本

Powershell: MaskedTextBox get Text

如何获取 Maskedtextbox 的纯文本?

例如像这样:

$Form = New-Object System.Windows.Forms.Form
$MaskedTextBox = New-Object System.Windows.Forms.MaskedTextBox
$MaskedTextBox.PasswordChar = '*'
$MaskedTextBox.Top = 100
$MaskedTextBox.Left = 80
$Form.Controls.Add($MaskedTextBox)
$Form.ShowDialog()

$MaskedTextBox.Text 包含您的输入。

您的 $form 缺少一个 OK/Cancel 按钮,参见 this example

所以简单地 copy/pasted 来自引用 link:

## Q:\Test18\SO_51841162.ps1
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

$Form = New-Object System.Windows.Forms.Form
$MaskedTextBox = New-Object System.Windows.Forms.MaskedTextBox
$MaskedTextBox.PasswordChar = '*'
$MaskedTextBox.Top = 100
$MaskedTextBox.Left = 80
$Form.Controls.Add($MaskedTextBox)

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = 'OK'
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)

$Result = $Form.ShowDialog()

if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
    $x = $MaskedTextBox.Text
    "Entered hidden password is: {0}" -f $x
}