powershell - 我们如何检查价值 $new_value1 = $inputpecentw1.Text。这个值可以吗?
问题描述
****我们如何更改代码行 $MaskedTextBox.PasswordChar = '*' 以检查数字值输入?我们如何限制powershell TextBox中减号和一个数字或一个数字的输入窗口大小?我们希望用户只能输入一个符号(减号)和一位数字或只能输入一位数字。为什么我们不能在 Windows 中使用退格键来删除旧值?
我们如何在窗口输入期间检查值 $new_value1 = $inputpecentw1.Text?这个值可以
只能是一个负数,例如 -5 且不超过 -9 或正数
数字例如 4 从 1 到 9 和 0
我生成的程序在 $Save_Click = { 之后不像设计那样工作
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$Form= New-Object system.Windows.Forms.Form
$Form.ClientSize = '800,800'
$Form.text = "Form"
$Form.TopMost = $false
$textnamef1 = New-Object 'System.Windows.Forms.Label'
$textPercent = New-Object 'System.Windows.Forms.Label'
$inputpecentw1 = New-Object 'System.Windows.Forms.MaskedTextBox'
$Read = New-Object 'System.Windows.Forms.Button'
$Save = New-Object 'System.Windows.Forms.Button'
$form_Load = {
$inputpecentw1.Text = [xml](Get-Content 'c:\program\MIK_Autokontinent.xml') | ForEach-Object { $_.SelectNodes(' //FieldCostOptions/IncreaseCost') | ForEach-Object { $_.GetAttribute("Percent") } } | Out-String
}
$Read_Click = {
$inputpecentw1.Text = [xml](Get-Content 'c:\program\MIK_Autokontinent.xml') | ForEach-Object { $_.SelectNodes(' //FieldCostOptions/IncreaseCost') | ForEach-Object { $_.GetAttribute("Percent") } } | Out-String
}
$Save_Click = {
IF ($inputpecentw1.Text -eq '^(\d|-\d)$'){
$new_value1 = $inputpecentw1.Text
[xml](Get-Content 'c:\program\MIK_Autokontinent.xml' -Encoding UTF8) | ForEach-Object { $_.SelectNodes(' //FieldCostOptions/IncreaseCost') | ForEach-Object { $_.SetAttribute("Percent", $new_value1) }; $_.Save('c:\program\MIK_Autokontinent.xml') }
}
Else{ $value=$inputpecentw1.Text
[System.Windows.MessageBox]::Show($value.ToString())
} }
$form.Controls.Add($textnamef1)
$form.Controls.Add($textPercent)
$form.Controls.Add($inputpecentw1)
$form.Controls.Add($Read)
$form.Controls.Add($Save)
$form.ClientSize = '800, 800'
$form.Text = 'проценты'
$form.add_Load($form_Load)
$textnamef1.AutoSize = $True
$textnamef1.Location = '80, 40'
$textnamef1.Text = 'MIK_Autokontinent.xml'
$textPercent.AutoSize = $True
$textPercent.Location = '120, 110'
$textPercent.Text = 'Percent'
$inputpecentw1.Location = '120, 140'
$inputpecentw1.Size = '20, 20'
$Read.Location = '20,740'
$Read.Size = '100, 40'
$Read.Text = 'Rread'
$Read.add_Click($Read_Click)
$Save.Location = '680,740'
$Save.Size = '100, 40'
$Save.Text = 'Save'
$Save.add_Click($Save_Click)
#Show the Form
$form.ShowDialog()
解决方案
您应该使用System.Windows.Forms.MaskedTextBox
而不是常规的 TextBox,然后分配Mask
属性。
这是可用掩码的文档。
推荐阅读
- java - 如果包名不同,则无法从导入的 jar 中调用方法
- micronaut - 在 micronaut 中创建可组合的存储库
- mysql - mysql - 创建前检查
- .net - 无法从 .NET 中的 app.config 检索 ConnectionString
- oauth - 向 eBay 发出简单的授权请求
- java - 如何对一组链接节点进行排序。(按优先级值对顺序链接的节点进行排序。)
- r - R 相当于 Stata 在宏上的 for 循环
- c++ - 终端不会为 C++ 文件创建 .exe 文件?
- pandas - 使用 GeoPandas 从点创建多边形
- asp.net-mvc - 我正在尝试下面给定的代码,但它显示错误 CS0051