请帮助
我向自己保证,我将自己解决这个问题,但是无论我尝试了什么,我似乎都无法弄清楚。我尝试过Google,所以也尝试了一些同事,但无济于事。
尝试运行GUI以便员工输入有关他们所执行的作业的信息,以使放入作业中的更新遵循特定的TEMPLATE格式。
示例:
上面是模板,工作人员会在模板后面加上“ A:”(依此类推)之后的文本。 我目前拥有的代码可以在下面找到。
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Windows.Forms.Application]::EnableVisualStyles()
$Form = New-Object system.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(900,320)
$Form.MaximizeBox = $false
$Form.StartPosition = "CenterScreen"
$Form.FormBorderStyle = 'Fixed3D'
$Form.Text = "Ticket Updates"
# ----------CREATE LABELS---------- #
$AssetLabel = New-Object System.Windows.Forms.Label
$AssetLabel.Text = "A:"
$AssetLabel.AutoSize = $true
$AssetLabel.Location = New-Object System.Drawing.Size(21,15)
$Font = New-Object System.Drawing.Font("Consolas",14,[System.Drawing.FontStyle]::Bold)
$Form.Font = $Font
$Form.Controls.Add($AssetLabel)
$ErrorLabel = New-Object System.Windows.Forms.Label
$ErrorLabel.Text = "E:"
$ErrorLabel.AutoSize = $true
$ErrorLabel.Location = New-Object System.Drawing.Size(21,50)
$Font = New-Object System.Drawing.Font("Consolas",14,[System.Drawing.FontStyle]::Bold)
$Form.Font = $Font
$Form.Controls.Add($ErrorLabel)
$IssueLabel = New-Object System.Windows.Forms.Label
$IssueLabel.Text = "I:"
$IssueLabel.AutoSize = $true
$IssueLabel.Location = New-Object System.Drawing.Size(21,85)
$Font = New-Object System.Drawing.Font("Consolas",14,[System.Drawing.FontStyle]::Bold)
$Form.Font = $Font
$Form.Controls.Add($IssueLabel)
$TestTagLabel = New-Object System.Windows.Forms.Label
$TestTagLabel.Text = "TT:"
$TestTagLabel.AutoSize = $true
$TestTagLabel.Location = New-Object System.Drawing.Size(10,120)
$Font = New-Object System.Drawing.Font("Consolas",14,[System.Drawing.FontStyle]::Bold)
$Form.Font = $Font
$Form.Controls.Add($TestTagLabel)
$TroubleshootLabel = New-Object System.Windows.Forms.Label
$TroubleshootLabel.Text = "TS:"
$TroubleshootLabel.AutoSize = $true
$TroubleshootLabel.Location = New-Object System.Drawing.Size(10,155)
$Font = New-Object System.Drawing.Font("Consolas",14,[System.Drawing.FontStyle]::Bold)
$Form.Font = $Font
$Form.Controls.Add($TroubleshootLabel)
$ResolutionLabel = New-Object System.Windows.Forms.Label
$ResolutionLabel.Text = "RW:"
$ResolutionLabel.AutoSize = $true
$ResolutionLabel.Location = New-Object System.Drawing.Size(10,190)
$Font = New-Object System.Drawing.Font("Consolas",14,[System.Drawing.FontStyle]::Bold)
$Form.Font = $Font
$Form.Controls.Add($ResolutionLabel)
# ----------END LABELS---------- #
# ----------CREATE TEXT BOXES---------- #
$AssetText = New-Object System.Windows.Forms.TextBox
$AssetText.Size = New-Object System.Drawing.Size(750,20)
$AssetText.Location = New-Object System.Drawing.Size(50,12)
$Font = New-Object System.Drawing.Font("Consolas",14,[System.Drawing.FontStyle]::Bold)
$Form.Font = $Font
$AssetText.Text = "<Asset Number(s)> - Asset number(s) of any affected equipment"
$Form.Controls.Add($AssetText)
$ErrorText = New-Object System.Windows.Forms.TextBox
$ErrorText.Size = New-Object System.Drawing.Size(750,20)
$ErrorText.Location = New-Object System.Drawing.Size(50,47)
$Font = New-Object System.Drawing.Font("Consolas",14,[System.Drawing.FontStyle]::Bold)
$Form.Font = $Font
$ErrorText.Text = "<Error Text> - Error message if applicable"
$Form.Controls.Add($ErrorText)
$IssueText = New-Object System.Windows.Forms.TextBox
$IssueText.Size = New-Object System.Drawing.Size(750,20)
$IssueText.Location = New-Object System.Drawing.Size(50,82)
$Font = New-Object System.Drawing.Font("Consolas",14,[System.Drawing.FontStyle]::Bold)
$Form.Font = $Font
$IssueText.Text = "<Issue Text> - What the technician's observation is"
$Form.Controls.Add($IssueText)
$TestTagText = New-Object System.Windows.Forms.TextBox
$TestTagText.Size = New-Object System.Drawing.Size(750,20)
$TestTagText.Location = New-Object System.Drawing.Size(50,117)
$Font = New-Object System.Drawing.Font("Consolas",14,[System.Drawing.FontStyle]::Bold)
$Form.Font = $Font
$TestTagText.Text = "<Test & Tag> - Were the power cables T&T compliant"
$Form.Controls.Add($TestTagText)
$TroubleshootText = New-Object System.Windows.Forms.TextBox
$TroubleshootText.Size = New-Object System.Drawing.Size(750,20)
$TroubleshootText.Location = New-Object System.Drawing.Size(50,152)
$Font = New-Object System.Drawing.Font("Consolas",14,[System.Drawing.FontStyle]::Bold)
$Form.Font = $Font
$TroubleshootText.Text = "<Troubleshooting> - What steps were performed during the resolution"
$Form.Controls.Add($TroubleshootText)
$ResolutionText = New-Object System.Windows.Forms.TextBox
$ResolutionText.Size = New-Object System.Drawing.Size(750,20)
$ResolutionText.Location = New-Object System.Drawing.Size(50,187)
$Font = New-Object System.Drawing.Font("Consolas",14,[System.Drawing.FontStyle]::Bold)
$Form.Font = $Font
$ResolutionText.Text = "<Resolution/Workaround> - How you fixed the problem"
$Form.Controls.Add($ResolutionText)
# ----------END TEXT BOXES---------- #
# ----------CREATE BUTTONS---------- #
$Resetbutton = New-Object System.Windows.Forms.Button
$Resetbutton.Location = New-Object System.Drawing.Size(810,11)
$Resetbutton.Size = New-Object System.Drawing.Size(70,30)
$Resetbutton.Text = "Reset"
$Resetbutton.Add_Click({$AssetText.Text = "<Asset Number(s)> - Asset number(s) of any affected equipment"
$ErrorText.Text = "<Error Text> - Error message if applicable"
$IssueText.Text = "<Issue Text> - What the technician's observation is"
$TestTagText.Text = "<Test & Tag> - Were the power cables T&T compliant"
$TroubleShootText.Text = "<Troubleshooting> - What steps were performed during the resolution"
$ResolutionText.Text = "<Resolution/Workaround> - How you fixed the problem"})
$Form.Controls.Add($Resetbutton)
$Copybutton = New-Object System.Windows.Forms.Button
$Copybutton.Location = New-Object System.Drawing.Size(810,187)
$Copybutton.Size = New-Object System.Drawing.Size(70,30)
$Copybutton.Text = "COPY"
$Copybutton.Add_Click({$TEMPLATE.Text.Trim() | Clip})
$Form.Controls.Add($Copybutton)
$Exitbutton = New-Object System.Windows.Forms.Button
$Exitbutton.Location = New-Object System.Drawing.Size(810,222)
$Exitbutton.Size = New-Object System.Drawing.Size(70,30)
$Exitbutton.Text = "Exit"
$Exitbutton.Add_Click({$Form.Close()})
$Form.Controls.Add($Exitbutton)
# ----------END BUTTONS---------- #
# ----------Text to Copy---------- #
$A = $AssetLabel + " " + $AssetText
$E = $ErrorLabel + " " + $ErrorText
$I = $IssueLabel + " " + $IssueText
$TT = $TestTagLabel + " " + $TestTagText
$TS = $TroubleshootLabel + " " + $TroubleshootText
$RW = $ResolutionLabel + " " + $ResolutionText
$TEMPLATE = $A, $E, $I, $TT, $TS, $RW
# ----------End Text to Copy---------- #
$Form.ShowDialog()
答案 0 :(得分:0)
您正在尝试连接整个 label
对象,而不是其.Text
属性。更改此:
$A = $AssetLabel + " " + $AssetText
$E = $ErrorLabel + " " + $ErrorText
$I = $IssueLabel + " " + $IssueText
$TT = $TestTagLabel + " " + $TestTagText
$TS = $TroubleshootLabel + " " + $TroubleshootText
$RW = $ResolutionLabel + " " + $ResolutionText
对此:
$A = $AssetLabel.Text + " " + $AssetText.Text
$E = $ErrorLabel.Text + " " + $ErrorText.Text
$I = $IssueLabel.Text + " " + $IssueText.Text
$TT = $TestTagLabel.Text + " " + $TestTagText.Text
$TS = $TroubleshootLabel.Text + " " + $TroubleshootText.Text
$RW = $ResolutionLabel.Text + " " + $ResolutionText.Text
也。您要将这部分放入.Add_Click
的{{1}}方法中。并使用其$Copybutton
方法将 Clip 更改为加速器类Windows.Clipboard
。
SetText
答案 1 :(得分:0)
移动“要复制的文本”块
AudioServicesPlayAlertSound
添加到# ----------Text to Copy---------- #
$A = $AssetLabel + " " + $AssetText
$E = $ErrorLabel + " " + $ErrorText
$I = $IssueLabel + " " + $IssueText
$TT = $TestTagLabel + " " + $TestTagText
$TS = $TroubleshootLabel + " " + $TroubleshootText
$RW = $ResolutionLabel + " " + $ResolutionText
$TEMPLATE = $A, $E, $I, $TT, $TS, $RW
块中,然后像这样添加text属性
$Copybutton.Add_Click({})
和您可能希望为每行输入使用的trim()。