Powershell:MaskedTextBox获取文本

时间:2018-08-14 12:13:04

标签: powershell passwords maskedtextbox

如何获取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()

2 个答案:

答案 0 :(得分:0)

$MaskedTextBox.Text包含您的输入。

答案 1 :(得分:0)

您的$ form缺少“确定/取消”按钮,请参见this example

因此只需从引用的链接中复制/粘贴:

## Q:\Test\2018\08\14\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
}