每次启动时运行的Powershell按钮';s咔嗒一声

每次启动时运行的Powershell按钮';s咔嗒一声,powershell,Powershell,我正在尝试获取一个密码按钮,以便在每次单击该按钮时生成新密码。第一次单击会生成一个符合我要求的密码,但每次单击都需要重新运行密码。我知道这可能是add\u click()中的一些简单内容,但我似乎找不到任何东西。下面是关于按钮和密码生成的所有信息 #form1: Button1 "password generate" $button1 = New-Object system.windows.forms.button $button1.location = "10, 25" $button1.s

我正在尝试获取一个密码按钮,以便在每次单击该按钮时生成新密码。第一次单击会生成一个符合我要求的密码,但每次单击都需要重新运行密码。我知道这可能是
add\u click()
中的一些简单内容,但我似乎找不到任何东西。下面是关于按钮和密码生成的所有信息

#form1: Button1 "password generate" 
$button1 = New-Object system.windows.forms.button
$button1.location = "10, 25"
$button1.size = "125, 35"
$button1.text = "Generate Password"
$button1.add_click($displayPassword)
$form1.controls.add($button1)

#######Password######

$caps = [char[]] "ABCDEFGHJKMNPQRSTUVWXY"
$lows = [char[]] "abcdefghjkmnpqrstuvwxy"
$nums = [char[]] "2346789"
$special = [char[]] "#%$+<=>?"

$first = Get-Random -Minimum 2 
$second = Get-Random -Minimum 2
$third = Get-Random -Miniumum 2 
$fourth = Get-Random -Minimum 2
$ofs = ""
$pwd = [string](@($caps | Get-Random -Count $first) + @($lows | Get-Random -Count $second) + @($nums | Get-Random -Count $third)+ @($special | Get-Random -Count $fourth) | Get-Random -Count 15)

$displayPassword = {$textbox1.text = "$pwd"}
#表单1:Button1“密码生成”
$button1=新对象system.windows.forms.button
$button1.location=“10,25”
$button1.size=“125,35”
$button1.text=“生成密码”
$button1.添加\单击($displayPassword)
$form1.controls.add($button1)
#######密码######
$caps=[char[]]“ABCDEFGHJKMNPQRSTUVWXY”
$lows=[char[]]“abcdefghjkmnpqrstuvwxy”
$nums=[char[]]“2346789”
$special=[char[]]“#%$+?”
$first=随机获取-最少2个
$second=随机获取-最少2个
$third=随机获取-最小值2
$fourth=随机获取-最少2个
$ofs=“”
$pwd=[string](@($caps | Get Random-Count$first)+@($lows | Get Random-Count$second)+@($nums | Get Random-Count$third)+@($special | Get Random-Count$fourth)| Get Random-Count 15)
$displayPassword={$textbox1.text=“$pwd”}

用于计算随机密码的所有内容只运行一次。click eventhandler仅更新文本框,但它从不重新生成新密码

试着这样做:

#form1: Button1 "password generate" 
$button1 = New-Object system.windows.forms.button
$button1.location = "10, 25"
$button1.size = "125, 35"
$button1.text = "Generate Password"
$button1.add_click({
    $first = Get-Random -Minimum 2 
    $second = Get-Random -Minimum 2
    $third = Get-Random -Miniumum 2 
    $fourth = Get-Random -Minimum 2
    $pwd = [string](@($caps | Get-Random -Count $first) + @($lows | Get-Random -Count $second) + @($nums | Get-Random -Count $third)+ @($special | Get-Random -Count $fourth) | Get-Random -Count 15)
    $textbox1.text = "$pwd"

})

$form1.controls.add($button1)

#######Static Password Resources######

$caps = [char[]] "ABCDEFGHJKMNPQRSTUVWXY"
$lows = [char[]] "abcdefghjkmnpqrstuvwxy"
$nums = [char[]] "2346789"
$special = [char[]] "#%$+<=>?"
$ofs = ""
#表单1:Button1“密码生成”
$button1=新对象system.windows.forms.button
$button1.location=“10,25”
$button1.size=“125,35”
$button1.text=“生成密码”
$button1.添加\单击({
$first=随机获取-最少2个
$second=随机获取-最少2个
$third=随机获取-最小值2
$fourth=随机获取-最少2个
$pwd=[string](@($caps | Get Random-Count$first)+@($lows | Get Random-Count$second)+@($nums | Get Random-Count$third)+@($special | Get Random-Count$fourth)| Get Random-Count 15)
$textbox1.text=“$pwd”
})
$form1.controls.add($button1)
#######静态密码资源######
$caps=[char[]]“ABCDEFGHJKMNPQRSTUVWXY”
$lows=[char[]]“abcdefghjkmnpqrstuvwxy”
$nums=[char[]]“2346789”
$special=[char[]]“#%$+?”
$ofs=“”

供参考,对于未来的问题,包括一个完整的工作样本。您的示例引用了从未声明的
$form1
$textbox1

用于计算随机密码的所有内容只运行一次。click eventhandler仅更新文本框,但它从不重新生成新密码

试着这样做:

#form1: Button1 "password generate" 
$button1 = New-Object system.windows.forms.button
$button1.location = "10, 25"
$button1.size = "125, 35"
$button1.text = "Generate Password"
$button1.add_click({
    $first = Get-Random -Minimum 2 
    $second = Get-Random -Minimum 2
    $third = Get-Random -Miniumum 2 
    $fourth = Get-Random -Minimum 2
    $pwd = [string](@($caps | Get-Random -Count $first) + @($lows | Get-Random -Count $second) + @($nums | Get-Random -Count $third)+ @($special | Get-Random -Count $fourth) | Get-Random -Count 15)
    $textbox1.text = "$pwd"

})

$form1.controls.add($button1)

#######Static Password Resources######

$caps = [char[]] "ABCDEFGHJKMNPQRSTUVWXY"
$lows = [char[]] "abcdefghjkmnpqrstuvwxy"
$nums = [char[]] "2346789"
$special = [char[]] "#%$+<=>?"
$ofs = ""
#表单1:Button1“密码生成”
$button1=新对象system.windows.forms.button
$button1.location=“10,25”
$button1.size=“125,35”
$button1.text=“生成密码”
$button1.添加\单击({
$first=随机获取-最少2个
$second=随机获取-最少2个
$third=随机获取-最小值2
$fourth=随机获取-最少2个
$pwd=[string](@($caps | Get Random-Count$first)+@($lows | Get Random-Count$second)+@($nums | Get Random-Count$third)+@($special | Get Random-Count$fourth)| Get Random-Count 15)
$textbox1.text=“$pwd”
})
$form1.controls.add($button1)
#######静态密码资源######
$caps=[char[]]“ABCDEFGHJKMNPQRSTUVWXY”
$lows=[char[]]“abcdefghjkmnpqrstuvwxy”
$nums=[char[]]“2346789”
$special=[char[]]“#%$+?”
$ofs=“”

供参考,对于未来的问题,包括一个完整的工作样本。您的示例引用了从未声明的
$form1
$textbox1

用于计算随机密码的所有内容只运行一次。click eventhandler仅更新文本框,但它从不重新生成新密码

试着这样做:

#form1: Button1 "password generate" 
$button1 = New-Object system.windows.forms.button
$button1.location = "10, 25"
$button1.size = "125, 35"
$button1.text = "Generate Password"
$button1.add_click({
    $first = Get-Random -Minimum 2 
    $second = Get-Random -Minimum 2
    $third = Get-Random -Miniumum 2 
    $fourth = Get-Random -Minimum 2
    $pwd = [string](@($caps | Get-Random -Count $first) + @($lows | Get-Random -Count $second) + @($nums | Get-Random -Count $third)+ @($special | Get-Random -Count $fourth) | Get-Random -Count 15)
    $textbox1.text = "$pwd"

})

$form1.controls.add($button1)

#######Static Password Resources######

$caps = [char[]] "ABCDEFGHJKMNPQRSTUVWXY"
$lows = [char[]] "abcdefghjkmnpqrstuvwxy"
$nums = [char[]] "2346789"
$special = [char[]] "#%$+<=>?"
$ofs = ""
#表单1:Button1“密码生成”
$button1=新对象system.windows.forms.button
$button1.location=“10,25”
$button1.size=“125,35”
$button1.text=“生成密码”
$button1.添加\单击({
$first=随机获取-最少2个
$second=随机获取-最少2个
$third=随机获取-最小值2
$fourth=随机获取-最少2个
$pwd=[string](@($caps | Get Random-Count$first)+@($lows | Get Random-Count$second)+@($nums | Get Random-Count$third)+@($special | Get Random-Count$fourth)| Get Random-Count 15)
$textbox1.text=“$pwd”
})
$form1.controls.add($button1)
#######静态密码资源######
$caps=[char[]]“ABCDEFGHJKMNPQRSTUVWXY”
$lows=[char[]]“abcdefghjkmnpqrstuvwxy”
$nums=[char[]]“2346789”
$special=[char[]]“#%$+?”
$ofs=“”

供参考,对于未来的问题,包括一个完整的工作样本。您的示例引用了从未声明的
$form1
$textbox1

用于计算随机密码的所有内容只运行一次。click eventhandler仅更新文本框,但它从不重新生成新密码

试着这样做:

#form1: Button1 "password generate" 
$button1 = New-Object system.windows.forms.button
$button1.location = "10, 25"
$button1.size = "125, 35"
$button1.text = "Generate Password"
$button1.add_click({
    $first = Get-Random -Minimum 2 
    $second = Get-Random -Minimum 2
    $third = Get-Random -Miniumum 2 
    $fourth = Get-Random -Minimum 2
    $pwd = [string](@($caps | Get-Random -Count $first) + @($lows | Get-Random -Count $second) + @($nums | Get-Random -Count $third)+ @($special | Get-Random -Count $fourth) | Get-Random -Count 15)
    $textbox1.text = "$pwd"

})

$form1.controls.add($button1)

#######Static Password Resources######

$caps = [char[]] "ABCDEFGHJKMNPQRSTUVWXY"
$lows = [char[]] "abcdefghjkmnpqrstuvwxy"
$nums = [char[]] "2346789"
$special = [char[]] "#%$+<=>?"
$ofs = ""
#表单1:Button1“密码生成”
$button1=新对象system.windows.forms.button
$button1.location=“10,25”
$button1.size=“125,35”
$button1.text=“生成密码”
$button1.添加\单击({
$first=随机获取-最少2个
$second=随机获取-最少2个
$third=随机获取-最小值2
$fourth=随机获取-最少2个
$pwd=[string](@($caps | Get Random-Count$first)+@($lows | Get Random-Count$second)+@($nums | Get Random-Count$third)+@($special | Get Random-Count$fourth)| Get Random-Count 15)
$textbox1.text=“$pwd”
})
$form1.controls.add($button1)
#######静态密码资源######
$caps=[char[]]“ABCDEFGHJKMNPQRSTUVWXY”
$lows=[char[]]“abcdefghjkmnpqrstuvwxy”
$nums=[char[]]“2346789”
$special=[char[]]“#%$+?”
$ofs=“”

供参考,对于未来的问题,包括一个完整的工作样本。您的示例引用从未声明过的
$form1
$textbox1

必须定义该引用和
$displayPassword