forms - 通过函数在powershell中更改变量值的问题
问题描述
我在 Powershell 中使用表单编写了一个简单的井字游戏,我遇到了这个问题:
我声明了描述按钮内容的字符串变量和一个定义轮到的布尔变量。后来在函数中,我想更改布尔变量,但它仍然保持不变。我完全是新手,所以我想为我的问题获得最简单的解释。
[string]$p1 = "n"
[string]$p2 = "n"
[string]$p3 = "n"
[string]$p4 = "n"
[string]$p5 = "n"
[string]$p6 = "n"
[string]$p7 = "n"
[string]$p8 = "n"
[string]$p9 = "n"
$who=$true
Function check1 ([string]$P){
if ($P -eq "n"){
if($who -eq $true){
$Button[0,0].Image=[System.Drawing.Image]::FromFile("C:\Users\klima\Desktop\SYOP\kolko.bmp")
$P="o"
$who=$false
}
}
else{
$Button[0,0].Image=[System.Drawing.Image]::FromFile("C:\Users\klima\Desktop\SYOP\krzyzyk.bmp")
$P="x"
$who=$true
}
}
Function check2 ($P){
if ($P -eq "n"){
if($who -eq $true){
$Button[0,1].Image=[System.Drawing.Image]::FromFile("C:\Users\klima\Desktop\SYOP\kolko.bmp")
$P="o"
$who=$false
}
}
else{
$Button[0,1].Image=[System.Drawing.Image]::FromFile("C:\Users\klima\Desktop\SYOP\krzyzyk.bmp")
$P="x"
}
}
稍后在代码中我向该按钮添加点击
$Button[0,o].Add_Click({check1($p1)})
$Wybor[0,1].Add_Click({check2($p2)})
我的意思是我想更改布尔变量但它没有这样做,有人可以解释一下为什么吗?
解决方案
推荐阅读
- javascript - 重复使用代码而不提交表单两次
- vba - 使用 VBA 插入分页符
- android - 捕捉到特定类型的 ItemView 的 RecyclerView
- python - 如何将来自 xampp 的 MYSql 用于 python 3?
- jsf - 如果 p:commandLink 触发器具有 AJAX 更新和侦听器属性,如何能够多次显示 ap:slideMenu?
- elasticsearch - 将现有 Hive 表连接到 Elasticsearch
- jmeter - 测试完成时 JMeter 保存结果
- c# - 使用 Windows 身份验证的代理连接
- ios - 选择后 UNNotificationAction 不会关闭
- excel - 乘以谷歌表格/excel上的常数