Button 具有按钮功能的窗口窗体powershell
我的函数带有“事件处理程序”,但我无法在$event中定义操作部分中的值Button 具有按钮功能的窗口窗体powershell,button,powershell,window,Button,Powershell,Window,我的函数带有“事件处理程序”,但我无法在$event中定义操作部分中的值 $event=Register-ObjectEvent $Button click -SourceIdentifier $clickV -action {write-host $buttonV } 我有按钮,但没有输出,请参见下面的函数param 如果我使用以下命令更改我的行: $event=Register-ObjectEvent $Button click -SourceIdentifier $clickV -act
$event=Register-ObjectEvent $Button click -SourceIdentifier $clickV -action {write-host $buttonV }
我有按钮,但没有输出,请参见下面的函数param
如果我使用以下命令更改我的行:
$event=Register-ObjectEvent $Button click -SourceIdentifier $clickV -action {write-host "OK"}
我有按钮和输出
欢迎任何帮助
嗨,我的论坛也有同样的问题。这就是我所做的,也许你可以改变我的例子。如果你需要我解释什么,请告诉我 带按钮的工作论坛并向论坛发出。
Function Button
{
param(
[int]$EmplXButton,
[int]$EmplYButton,
[innt]$LongButton,
[int]$LargButton,
[string]$ButtonName,
[string]$clickV,
[int]$ButtonV
)
$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Size($EmplXButton,$EmplYButton)
$Button.Size = New-Object System.Drawing.Size($LongButton,$LargButton)
$Button.Text = $ButtonName
$event=Register-ObjectEvent $Button click -SourceIdentifier $clickV -action {
write-host $buttonV ; Unregister-Event $clickV
}
$Button.Add_Click({$objForm.Close()})
$objForm.Controls.Add($Button)
}
Button 20 60 90 23 zero clickV0 0
Button 115 60 90 23 one clickV1 1
Button 210 60 90 23 two clickV2 2
Button 305 60 90 23 three clickV3 3
#>
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
#Generated Form Function
function GenerateForm {
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#region Generated Form Objects
$MainForum = New-Object System.Windows.Forms.Form
$GetServices = New-Object System.Windows.Forms.Button
$richTextBox1 = New-Object System.Windows.Forms.RichTextBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$MainForum.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 262
$System_Drawing_Size.Width = 461
$MainForum.ClientSize = $System_Drawing_Size
$MainForum.DataBindings.DefaultDataSourceUpdateMode = 0
$MainForum.Name = "MainForum"
$MainForum.Text = "Demo GUI"
$GetServices.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 26
$GetServices.Location = $System_Drawing_Point
$GetServices.Name = "GetServices"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 75
$GetServices.Size = $System_Drawing_Size
$GetServices.TabIndex = 1
$GetServices.Text = "GetServices"
$GetServices.UseVisualStyleBackColor = $True
$GetServices.add_Click({ GetServices($GetServices) })
$richTextBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 132
$richTextBox1.Location = $System_Drawing_Point
$richTextBox1.Name = "richTextBox1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 118
$System_Drawing_Size.Width = 437
$richTextBox1.Size = $System_Drawing_Size
$richTextBox1.TabIndex = 0
$richTextBox1.Text = "Results Out Put To This Box"
$MainForum.Controls.Add($richTextBox1)
$MainForum.Controls.Add($GetServices)
#endregion
function GetServices($object)
{
OutputText
}
function OutputText($object)
{
$service = (Get-Service s*)
foreach ($_ in $service)
{
$name = $_.Name
$status = $_.Status
$richTextBox1.Text = $richTextBox1.Text + $name + " " +$status + "`r"
}
}
#Save the initial state of the form
$InitialFormWindowState = $MainForum.WindowState
#Init the OnLoad event to correct the initial state of the form
$MainForum.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$MainForum.ShowDialog()| Out-Null
} #End Function
#Call the Function
GenerateForm