我正在尝试使用PowerShell将文本框中输入的值输出到HTML,但我有点卡住了。这是我的代码:
$button1 = New-Object System.Windows.Forms.Button
$button1.Name = "button1"
$button1.Location = New-Object System.Drawing.Point(16, 350)
$button1.Text = "Create"
$button1.add_Click({ConvertTo-HTML -title "Email Signature" -body "<p>$textBox2.Text</p>"})
生成的HTML是......
System.Windows.Forms.TextBox, Text: Chris.Text
如何将输出简单地设为“Chris
”?
答案 0 :(得分:0)
完成了工作:)
答案是:$($ textBox2.Text)
答案 1 :(得分:0)
您可以将变量包装在()或{}中,以便在括在“”。
中时检索该值例如,
$button1.add_Click({ConvertTo-HTML -title "Email Signature" -body "<p>$($textBox2.Text)</p>"})
或
$button1.add_Click({ConvertTo-HTML -title "Email Signature" -body "<p>${textBox2.Text}</p>"})