這是一個基本的窗體窗體,其中包含一些按鈕,應該將它們複製到Clickboard,無論何時單擊該變量,它都會工作一次,然後按鈕停止響應,任何想法爲什麼?使用clip.exe的Windows窗體按鈕一次性工作並停止
的代碼是:
Add-Type -AssemblyName System.Windows.Forms
$Form = New-Object System.Windows.Forms.Form
$Form.Text = "Click2Copy :)"
$Font = New-Object System.Drawing.Font ("Roman", 11, [System.Drawing.FontStyle]::Regular)
$Form.Font = $Font
$Form.AutoSize = $false
$Form.AutoSizeMode = "GrowAndShrink"
$Form.MinimizeBox = $false
$Form.MaximizeBox = $false
$Form.WindowState = "Normal"
$Form.SizeGripStyle = "Hide"
$Form.ShowInTaskbar = $false
$Form.Opacity = 0.8
$form.StartPosition = "CenterScreen"
$form.BackColor = "black"
#$Label = New-Object System.Windows.Forms.Label
#$label.Location = New-Object Drawing.point 30,100
#$Label.Text = "Click a button to copy its content"
#$Label.AutoSize = $true
#$Label.ForeColor = "White"
$button = New-Object Windows.Forms.Button
$button.text = "Server-One-Example"
$button.ForeColor = "White"
$button.AutoSize = $true
$button.Location = New-Object Drawing.Point 65,10
$copy1 = "Server-One-Example" | clip.exe
$button.Add_Click($copy1)
$button2 = New-Object Windows.Forms.Button
$button2.text = "Server-Two-Example"
$button2.ForeColor = "White"
$button2.AutoSize = $true
$button2.Location = New-Object Drawing.Point 65,40
$copy2 = "Server-Two-Example" | clip.exe
$button2.Add_Click($copy2)
#$Form.controls.add($label)
$form.controls.add($button)
$form.controls.add($button2)
$Form.ShowDialog()
如果你會做一點嘗試,你會發現,與代碼,因爲它是在這裏,點擊按鈕也絕對沒有什麼。把「asdf」放在你的剪貼板上,然後運行你的程序,不要點擊任何東西。現在從剪貼板粘貼到記事本中,您會看到它上面有「Server-Two-Example」。運行管道輸出到clip.exe的行在程序運行時運行 - 它們沒有「連線」到按鈕單擊事件。 –